If statement not giving the desired output
조회 수: 1 (최근 30일)
이전 댓글 표시
I am using a simple if statement but it is not returning the correct result even when the condition is satisfied. No errors are showing.
e and M are user defined and converted from string to double using str2double on input!
M_1=[[]];
for i=1:1:size(M,1)
for j = 1:1:size(M,2)
if (M(i,j)< 157.02 + e)& (M(i,j)>157.02- e)
M_1 (i,j) = "A";
else
M_1(i,j) = "0";
end
end
end
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 10월 18일
Writing
M_1=[[]]
define it as an empty double array. Try following code
M = 200*rand(5); % example values
e = 5;
M_1=strings(size(M));
for i=1:1:size(M,1)
for j = 1:1:size(M,2)
if (M(i,j)< 157.02 + e) && (M(i,j)>157.02- e)
M_1 (i,j) = "A";
else
M_1(i,j) = "0";
end
end
end
댓글 수: 6
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!