Dimensions of matrices being concatenated are not consistent ?
조회 수: 1 (최근 30일)
이전 댓글 표시
% 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/330716/image.jpeg)
댓글 수: 0
채택된 답변
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
2020년 7월 12일
편집: madhan ravi
2020년 7월 12일
In that case:
g = [g.'; nan(numel(e) - numel(g), 1)]
추가 답변 (1개)
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!