# Dimensions of matrices being concatenated are not consistent ?

조회 수: 10(최근 30일)
Cristian Martin 12 Jul 2020
댓글: Cristian Martin 12 Jul 2020
% 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 12 Jul 2020
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

Cristian Martin 12 Jul 2020
You are correct, these are double arrays. So it's not possible to have a function that can read the number of columns for each array and display only for them. For example if one of array are only 13 columns display only 13 columns for all arrays.
If I do like this is ok,
result=[c(1:13);d(1:13);e(1:13);f(1:13);g(1:13)];
but every time the number of columns are different...and I don't know how many columns are every time.
In that case:
g = [g.'; nan(numel(e) - numel(g), 1)]
Cristian Martin 12 Jul 2020
Thank a lot Ravi, this is what I looking for !

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

Walter Roberson 12 Jul 2020
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 12 Jul 2020
Thanks Walter, I'll try your method also !

댓글을 달려면 로그인하십시오.

R2016a

Translated by