Dimensions of matrices being concatenated are not consistent ?

1 回表示 (過去 30 日間)
Cristian Martin
Cristian Martin 2020 年 7 月 12 日
コメント済み: Cristian Martin 2020 年 7 月 12 日
% How can I display the result in the following example. Not all time the strings are equals,
%but I need to display one below the other even at the end one even one is missing, it is possible?
c=[23;33;33;44;55;66;77;88;99;00;11;22;33;44];% 14 numbers
d=[23;33;33;44;55;66;77;88;34;00;11;44;33;44];% 14 numbers
e=[23;33;33;44;45;66;77;88;99;00;11;22;23;44];% 14 numbers
f=[23;33;33;44;53;66;77;88;99;04;11;22;33;44];% 14 numbers
g=[23;33;33;45;53;66;77;88;99;04;11;22;33;]; % as you can see this string is only 13 numbers
c=c';
d=d';
e=e';
f=f';
g=g';
result=[c;d;e;f;g];
Error:
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in Runscript (line 11)
result=[c;d;e;f;g];
%%I would like the result like in following picture below

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 12 日
編集済み: madhan ravi 2020 年 7 月 12 日
You cannot have holes in a matrix so append NaN at the end. By the way you refer to them as string but in fact they are double array. But if they were string appending "" at the end of g would do it.
  3 件のコメント
madhan ravi
madhan ravi 2020 年 7 月 12 日
編集済み: madhan ravi 2020 年 7 月 12 日
In that case:
g = [g.'; nan(numel(e) - numel(g), 1)]
Cristian Martin
Cristian Martin 2020 年 7 月 12 日
Thank a lot Ravi, this is what I looking for !

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 7 月 12 日
I notice that you are using R2016a, so I will not mention some of the possibilities for later releases
You cannot do that with a numeric array.
If you convert it to a cell array of numbers, and leave some entries empty, then you can cell2table() and writetable()
You can use dlmwrite() with append set, to write one line of values at a time.
You can experiment with putting in nan for the entries that you want to be blank, and convert to table, and use writetable(). At some point, nan started being writen out as empty, but I am not sure how early that was.
If this is for uitable for display purposes, then you can create a cell array of character vectors, leaving some of the cells empty, and setting the uitable Data property to the cell. If you do this, then if you permit editing the user will be able to enter text instead of numeric; you will need to str2double() and check for nan if you accept input on the uitable.
You will not be able to do what you want with the Variable Brower.
  1 件のコメント
Cristian Martin
Cristian Martin 2020 年 7 月 12 日
Thanks Walter, I'll try your method also !

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by