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)
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

Sign in to comment.

Accepted Answer

Walter Roberson
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

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!