Writing complex term in matlab in simple way
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi guys,
Im trying to do the same concept of what my code below does, but in a simple approach with different way.
my code in matlab is:
y=[1 -1 1 -1 -1 3 -4 5 -5]; %an array of integer values
output=+(y>0); %output result
So I want to do the same concept of what my code above does but simple approach/way in matlab like using for loop or whatever simple way(exactly the term +(y>0) is a complex term and need it to be more simplified with simple code row in matlab)
Could anyone please help me out on this? appreciated!
댓글 수: 0
채택된 답변
Walter Roberson
2020년 12월 25일
output = zeros(size(y)) ;
for K=1:numel(y)
if y(K) > 0
output(K) = 1;
end
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!