フィルターのクリア

manual script for loop

1 回表示 (過去 30 日間)
Augusto Gabriel da Costa Pereira
Augusto Gabriel da Costa Pereira 2023 年 2 月 9 日
編集済み: Jan 2023 年 2 月 9 日
I made this script just below but it is quite manual, I tried several ways to perform a loop, I was not successful in my action.
does anyone have an idea?
I used the matrix "tNino1_2" attached
MedComb(:,1)=1:1:15;
MedComb(1:1:15,2:1:6)=NaN;
xcol=20:1:24;
[r,c] = find(tNino1_2(:,xcol)==1);
[ru,ia,ic] = unique(r);
out = tNino1_2(ru,:);
out1AF = out1(out1(:,20)==1,[4,20])
MedComb(1,2)=nanmean(out1AF(:,1));
xcol=20:1:24;
[r,c] = find(tNino1_2(:,xcol)==2);
[ru,ia,ic] = unique(r);
out2 = tNino1_2(ru,:);
out2AF = out2(out2(:,20)==2,[4,20])
MedComb(2,2)=nanmean(out2AF(:,1));
xcol=20:1:24;
[r,c] = find(tNino1_2(:,xcol)==1);
[ru,ia,ic] = unique(r);
out = tNino1_2(ru,:);
out1RB = out1(out1(:,21)==1,[4,21])
MedComb(1,3)=nanmean(out1RB(:,1));
xcol=20:1:24;
[r,c] = find(tNino1_2(:,xcol)==2);
[ru,ia,ic] = unique(r);
out = tNino1_2(ru,:);
out2RB = out2(out2(:,21)==2,[4,21])
MedComb(2,3)=nanmean(out2RB(:,1));

採用された回答

Jan
Jan 2023 年 2 月 9 日
MedComb(:,1) = 1:15;
MedComb(1:15,2:6) = NaN;
xcol = 20:24;
for i1 = 1:2
for i2 = 0:1
[r, c] = find(tNino1_2(:, xcol) == i1);
ru = unique(r);
out = tNino1_2(ru, :); % A typo? "out" is defined, but "out1" used?!
out = out(out(:, 20 + i2) == i1, [4, 20 + i2])
MedComb(i1, 2 + i2) = nanmean(out(:, 1));
end
end
  2 件のコメント
Augusto Gabriel da Costa Pereira
Augusto Gabriel da Costa Pereira 2023 年 2 月 9 日
Amazing loop, thanks for another help!
Jan
Jan 2023 年 2 月 9 日
編集済み: Jan 2023 年 2 月 9 日
You are welcome. As far as I can see, this:
[r, c] = find(tNino1_2(:, xcol) == i1);
ru = unique(r);
can be simplified to:
ru = any(tNino1_2(:, xcol) == i1, 1);

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by