Clear Filters
Clear Filters

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

1 view (last 30 days)
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!

Accepted Answer

Walter Roberson
Walter Roberson on 9 Feb 2018
mask = R ~= 0;
R(mask) = R(mask) + 1;
  4 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!