x=linspace(0,8,91);
y=linspace(1,3,56);
I have a matrix DL1 (91x46) and need to extract DL2 =DL1(DL1<=2) and the values of the x and y axis from DL1 corresponding to DL2.
Please help

 採用された回答

KSSV
KSSV 2020 年 8 月 14 日
編集済み: KSSV 2020 年 8 月 14 日

0 投票

[m,n] =size(DL1)
x=linspace(0,8,n);
y=linspace(1,3,m);
[X,Y] = meshgrid(x,y) ;
%
idx = DL1<2 ;
idx = idx' ;
iwant = [X(idx) Y(idx)]

8 件のコメント

Asliddin Komilov
Asliddin Komilov 2020 年 8 月 14 日
I have pasted it into command window, it says:
Index exceeds matrix dimensions.
KSSV
KSSV 2020 年 8 月 14 日
Missed one line in the code......edited the answer.
Asliddin Komilov
Asliddin Komilov 2020 年 8 月 14 日
thanks, you have saved me a lot of time
Asliddin Komilov
Asliddin Komilov 2020 年 8 月 14 日
uups, how come DL2 =DL1(DL1<=2) becomes an array, how do I keep it as a matrix?
KSSV
KSSV 2020 年 8 月 14 日
You cannot keep it as a matrix..it will become a vector. If you want it to be matrix,, the option is make other elements NaN's.
idx = DL1<=2 ;
DL2 = DL1 ;
DL2(~idx) = NaN ;
Asliddin Komilov
Asliddin Komilov 2020 年 8 月 14 日
isn't possible to extract values of DL1 corresponding to X(idx) and Y(idx) in shape of a matrix?
Asliddin Komilov
Asliddin Komilov 2020 年 8 月 14 日
or extract x and y values for the none NaN part of the DL2?
KSSV
KSSV 2020 年 8 月 14 日
X(~idx) = NaN ;
Y(~idx) = NaN ;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2020 年 8 月 14 日

コメント済み:

2020 年 8 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by