Error using vertcat Dimensions of matrices being concatenated are not consistent.
2 views (last 30 days)
Show older comments
Good day. I am making a gui about the brayton cycle with input parameters. I am trying to display the previous parameters in a uitable but the error keeps popping out. This is the piece of code in my callback function.
Prev_val = [r_p,T_3c,n_comp * 100,n_turb * 100,n_th,W_net];
Prev_val = [Prev_val; get(handles.Prev_calc, 'data')];
set(handles.Prev_calc,'data',Prev_val);
When I run the program by commenting out line 2 first then bringing it back the error is not appearing.
0 Comments
Accepted Answer
Matt J
on 29 Dec 2016
Edited: Matt J
on 29 Dec 2016
One way to trap the error is to insert code as follows
Prev_val = [r_p,T_3c,n_comp * 100,n_turb * 100,n_th,W_net];
columns1 = size(Prev_val , 2);
columns2 = size( get(handles.Prev_calc, 'data') , 2 );
if columns1~=columns2
disp 'Unexpected size mismatch'
columns1, columns2,
keyboard
end
Prev_val = [Prev_val; get(handles.Prev_calc, 'data')];
When you re-run, the code will stop at the point just before the error occurs, allowing you to inspect the sizes of the matrices you are trying to concatenate and analyze what led to them being that way. You can accomplish much the same thing by Setting Breakpoints.
6 Comments
Matt J
on 29 Dec 2016
Edited: Matt J
on 29 Dec 2016
Well, it's very strange that you would get that particular error messagefrom vertcat.
But basically, the problem is that you are trying to join a numeric variable "Out" to the cell array of strings, "data". They both need to be cell arrays.
One possibility is to convert 'Out" to a cell array of strings as well,
OutCell=textscan(num2str(Out),'%s');
data = [data; OutCell{1}.'];
A different possibility is to split Out into cells, but keep the cell contents in numeric form,
data = [data; num2cell(Out)];
Which one you need depends what you are going to do with the concatenated data later.
More Answers (1)
KSSV
on 29 Dec 2016
[ones(2,1) ; ones(1,3)]
The above will throw a error, as dimensions are not compatible to join/concatenate. Where as the below
[ones(2,1) ; ones(3,1)]
works, as the dimensions of matrices are compatible to join. Check the dimensions of your matrices which you are joining.
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!