Error using cat Dimensions of arrays being concatenated are not consistent. Error in cell2mat m{n} = cat(1,c{:,n});
Show older comments
I'm trying to make an error bar plot with experimental data. i have used cell2table function to make a table some of the values on the table have [x,x] values like this with corresponding [y,y] and some of them are single values regardless i need to plot all of them against each other along with their error bars. but i keep getting this error on matlab.
% Scatter plot with error bars
figure;
errorbar(cell2mat(dataTable.FrictionAngle), cell2mat(dataTable.Cohesion), cell2mat(dataTable.Cohesion) - cell2mat(dataTable.CohesionMin), cell2mat(dataTable.CohesionMax) - cell2mat(dataTable.Cohesion), cell2mat(dataTable.FrictionAngle) - cell2mat(dataTable.FrictionAngleMin), cell2mat(dataTable.FrictionAngleMax) - cell2mat(dataTable.FrictionAngle), 'o');
please help
3 Comments
Steven Lord
on 22 May 2024
Can you save the dataTable variable to a MAT-file and attach it to your post? Edit your message (or add a comment) and use the paper clip button in the Insert section of the Toolstrip to attach the file.
Also please include the full and exact text of the error message (all the text displayed in the Command Window in red) in a comment. Don't paraphrase, don't summarize, don't truncate, copy and paste the full message.
My suspicion is that one or more of the variables in your table has a different size than you think they do and that's causing cell2mat (which shouldn't be necessary if your data is numeric) to return something differently sized.
AMANATH Hassan
on 22 May 2024
AMANATH Hassan
on 22 May 2024
Accepted Answer
More Answers (1)
Venkat Siddarth Reddy
on 22 May 2024
Edited: Venkat Siddarth Reddy
on 22 May 2024
Hi Amanath,
The error is due to inconsistents in the sizes of elements wthin the cell arrays dataTable.Cohesion and dataTable.FrictionAngle .
For a successful conversion of a cell array into a MATLAB array, it's neccessary that all cells are of uniform size. However in the columns mentioned, there's a mix of single-element cells alongside cells containing two elements. This discrepancy in cell sizes is what led MATLAB to generate an error.
load("dataTable")
dataTable.Cohesion([1 2])
%Similarly for FrictionAngle
dataTable.FrictionAngle([1 2])
Hope its clear
Categories
Find more on Time Series Events 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!
