manual script for loop
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Augusto Gabriel da Costa Pereira
il 9 Feb 2023
Modificato: Jan
il 9 Feb 2023
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));
0 Commenti
Risposta accettata
Jan
il 9 Feb 2023
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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!