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 件のコメント
Thi Ng
Thi Ng 2020 年 4 月 22 日
Thank you very much! Works perfectly.
Thi Ng
Thi Ng 2020 年 4 月 22 日
I would mark the answers as accepted, but they are all in the comments. Many thanks!

サインインしてコメントする。

採用された回答

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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by