Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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!

Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Feb. de 2018
mask = R ~= 0;
R(mask) = R(mask) + 1;
  4 comentarios
Walter Roberson
Walter Roberson el 9 de Feb. de 2018
for K = 1 : length(R)
if R(K) > 0; R(K) = R(K) + 1; end
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by