How do I take a "for loop" answer and put it to an "if" statement command?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Phi Tran
am 9 Feb. 2018
Kommentiert: Phi Tran
am 9 Feb. 2018
TNY =[31, 26, 30, 33, 33, 39, 41, 41, 34, 33, 45, 42, 36, 39, 37, 45,43, 36, 41, 37, 32, 32, 35, 42, 38, 33, 40, 37, 36, 51, 50];
TAN =[37, 24, 28, 25, 21, 28, 46, 37, 36, 20, 24, 31, 34, 40, 43, 36, 34, 41, 42, 35, 38, 36, 35, 33, 42, 42, 37, 26, 20, 25, 31];
X = mean(TNY)< TNY;
Y= mean(TAN)< TAN;
sum(X);
sum(Y);
R = zeros(size(TNY));
for i = 1:length(TAN)
R = R + (TNY==TAN(1,i));
end
R
%%R= 2 1 0 1 1 0 1 1.........
% I want to add 1 to any number that is not 0.
% I've tried
if R>0
R+1
end
That doesn't work.
Help!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 9 Feb. 2018
mask = R ~= 0;
R(mask) = R(mask) + 1;
4 Kommentare
Walter Roberson
am 9 Feb. 2018
for K = 1 : length(R)
if R(K) > 0; R(K) = R(K) + 1; end
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!