フィルターのクリア

how do i get MATLAB to extract a specific value in multidimension array or matrix

3 ビュー (過去 30 日間)
Hi, i have a matric 420x32x20
then i want to extract the value form -1 to -4
thus, i tried
for i=1:32
for j=1:20
idx(:,i,j)=CHIRPS_SPI3_SM(:,i,j)<-1 & CHIRPS_SPI3_SM(:,i,j)>-4;
end
end
but i came out as 1 and 0 only. But, how can I use MATLAB to extract and save the actual value of -1 till -4?
  5 件のコメント
Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria 2021 年 4 月 22 日
I want it to be in precipxlonxlat too as i need to produce a spatial figure. Can I?
Walter Roberson
Walter Roberson 2021 年 4 月 22 日
Not typically, no. In some cases, the values in the range you want all happen to form a nice hypercube, and in that case you could extract the hypercube. However, most of the time, there will be values that are not wanted that are mixed in with the values that are wanted, and in that case the best you could do would be to find the "bounding box" -- the smallest axis-alighted cuboid that contains all the values you want, but also contains some values that you do not want.

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

回答 (2 件)

Matt J
Matt J 2021 年 4 月 20 日
idx=CHIRPS_SPI3_SM<-1 & CHIRPS_SPI3_SM>-4;
extractedValues=CHIRPS_SPI3_SM(idx);
  2 件のコメント
Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria 2021 年 4 月 20 日
can i apply this for, i want it in my matrix 420x32x20, I want to find the value for each grid
Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria 2021 年 4 月 20 日
i have tried as above before sir, but i need it to calculate for each grid to map later

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


Walter Roberson
Walter Roberson 2021 年 4 月 22 日
編集済み: Walter Roberson 2021 年 4 月 22 日
If you want the bounding box, then
mask = CHIRPS_SPI3_SM<-1 & CHIRPS_SPI3_SM>-4; %m x n x p
mask1 = any(mask,1); %1 x n x p
mask13 = any(mask1,3); %1 x n x 1
cmin = find(mask13,1,'first');
cmax = find(mask13,1,'last');
mask23 = any(any(mask,2),3); %m x 1 x 1
rmin = find(mask23,1,'first');
rmax = find(mask23,1,'last');
mask12 = any(mask1,2); %1 x 1 x p
pmin = find(mask12,1,'first');
pmax = find(mask12,1,'last');
bounds = [cmin cmax rmin rmax pmin pmax];
subset = CHIRPS_SPI3_SM(cmin:cmax, rmin:rmax, pmin:pmax);
  9 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 23 日
No, I mean just plain
reshape([1 2], [], 1)
I want to know if reshape() works for you even in very simple cases.
If not, then use
restoredefaultpath
rehash toolboxcache
Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria 2021 年 4 月 23 日
its working sir! thank you very much!

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by