How do I take a "for loop" answer and put it to an "if" statement command?

1 次查看(过去 30 天)
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!

采纳的回答

Walter Roberson
Walter Roberson 2018-2-9
mask = R ~= 0;
R(mask) = R(mask) + 1;
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by