How to solve 'Error using vertcat, Dimensions of arrays being concatenated are not consistent.'? But they have the same dimensions.

1 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-4-22
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 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by