How to solve 'Error using vertcat, Dimensions of arrays being concatenated are not consistent.'? But they have the same dimensions.
1 view (last 30 days)
Show older comments
Thi Ng
on 22 Apr 2020
Answered: Walter Roberson
on 22 Apr 2020
Hi Everyone,
This error occurs whenever I have changed a value in my table to 0 or above 10. Whenever I have values between 1 and 9 the code works. What could be the reason for this and any suggestion on how can I make it work for 0?
Thanks,
8 Comments
Accepted Answer
Walter Roberson
on 22 Apr 2020
M1_6_A1 = [ 0 0 0 ];
if t1(1,1) == 0
elseif t1(1,1) == 1
M1_6_A1 = [ 0 0 1 ];
elseif t1(1,1) == 2
M1_6_A1 = [ 0.1 0.5 0.8 ];
elseif t1(1,1) == 3
M1_6_A1 = [ 0 0.9 1 ];
elseif t1(1,1) == 4
M1_6_A1 = [ 0.2 0.8 0.8 ];
elseif t1(1,1) == 5
M1_6_A1 = [ 0.2 0.8 0.3 ];
elseif t1(1,1) == 6
M1_6_A1 = [ 0.7 0.9 0.2 ];
elseif t1(1,1) == 7
M1_6_A1 = [ 0.9 1 0 ];
elseif t1(1,1) == 8
M1_6_A1 = [ 0.9 0.5 0 ];
elseif t1(1,1) == 9
M1_6_A1 = [ 1 0 0 ];
else
M1_6_A1 = [ 1 1 1 ];
end
No for loop needed.
You could rewrite as
if t1(1,1) == 0
M1_6_A1 = [ 0 0 0 ];
elseif t1(1,1) == 1
M1_6_A1 = [ 0 0 1 ];
elseif t1(1,1) == 2
M1_6_A1 = [ 0.1 0.5 0.8 ];
elseif t1(1,1) == 3
M1_6_A1 = [ 0 0.9 1 ];
elseif t1(1,1) == 4
M1_6_A1 = [ 0.2 0.8 0.8 ];
elseif t1(1,1) == 5
M1_6_A1 = [ 0.2 0.8 0.3 ];
elseif t1(1,1) == 6
M1_6_A1 = [ 0.7 0.9 0.2 ];
elseif t1(1,1) == 7
M1_6_A1 = [ 0.9 1 0 ];
elseif t1(1,1) == 8
M1_6_A1 = [ 0.9 0.5 0 ];
elseif t1(1,1) == 9
M1_6_A1 = [ 1 0 0 ];
else
M1_6_A1 = [ 1 1 1 ];
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical 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!