If statement not giving the desired output
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Ameer Hamza
on 18 Oct 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Whos 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!