Hi. Is it possible that I want to,
Change the value of -1.00 untill -3.00 tu 1 and the rest as 0. Then, I want to know how much 1 in each grid, how can I calculate how much amount of 1?

 採用された回答

KSSV
KSSV 2021 年 4 月 2 日

1 投票

Let A be your matrix/ grid.
idx = A<-1 & A>-3 ;
A(idx) = 1 ;
A(~idx) = 0 ;
nnz(A==1)
nnz(A==0)

5 件のコメント

Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria 2021 年 4 月 2 日
for i=1:5
for j=1:11
YES(:,i,j) = nnz((idx(:,i,j))==1);
NO(:,i,j) = nnz((idx(:,i,j))==0);
end
end
Then,
for i=1:5
for j=1:11
Freq(:,i,j)=YES(:,i,j)/420;
end
end
Lastly,
for i=1:5
for j=1:11
New_freq(:,i,j)=Freq(:,i,j)*100;
end
end
Is this okay?
I want to apply this formula for each grid:
Frequency=num of drought months/total month*100
As I want to plot it spatially.
Anyone can please help me?
KSSV
KSSV 2021 年 4 月 2 日
You need not to apply a loop. You can do all at once.
Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria 2021 年 4 月 2 日
But, is my way above is okay? Im not really good at looping yet
KSSV
KSSV 2021 年 4 月 2 日
yes = 0 ; no = 0 ;
for i=1:5
for j=1:11
if idx(i,j)==1
yes = yes+1 ;
elseif idx(i,j) == 0
no = no+1 ;
end
end
end
Nurul Ain Basirah Zakaria
Nurul Ain Basirah Zakaria 2021 年 4 月 7 日
sir, thank you very much. i will try to understand looping better

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by