필터 지우기
필터 지우기

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
Walter Roberson
Walter Roberson 2018년 2월 9일
for K = 1 : length(R)
if R(K) > 0; R(K) = R(K) + 1; end
end

댓글을 달려면 로그인하십시오.

추가 답변 (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