Error using cat Dimensions of arrays being concatenated are not consistent. Error in cell2mat m{n} = cat(1,c{:,n});

6 ビュー (過去 30 日間)
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 件のコメント
AMANATH Hassan
AMANATH Hassan 2024 年 5 月 22 日
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
Error in phiC (line 113)
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');
^this is the whole message in the command window

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

採用された回答

Voss
Voss 2024 年 5 月 22 日
編集済み: Voss 2024 年 5 月 22 日
load dataTable
NC = cellfun(@numel,dataTable.Cohesion);
Cmin = repelem(dataTable.CohesionMin,NC,1);
Cmax = repelem(dataTable.CohesionMax,NC,1);
NFA = cellfun(@numel,dataTable.FrictionAngle);
FAmin = repelem(dataTable.FrictionAngleMin,NFA,1);
FAmax = repelem(dataTable.FrictionAngleMax,NFA,1);
FA = [dataTable.FrictionAngle{:}].';
C = [dataTable.Cohesion{:}].';
% Scatter plot with error bars
figure
errorbar(FA,C,C-Cmin,Cmax-C,FA-FAmin,FAmax-FA,'o');
  14 件のコメント
AMANATH Hassan
AMANATH Hassan 2024 年 5 月 25 日
Okay, thank you once again :) you are so helpful!!
Peter Perkins
Peter Perkins 2024 年 5 月 29 日
Voss said, "The types and sizes of data stored in this table are quite different than the original table"
One big difference is that in dataTable, Cohesion and FrictionAngle are "ragged", with some rows having two values and others only one, while in MarsRegolith, those both have two values in every row. Using cell arrays is a necessary complication in the former, while it is just overcomplicating things in the latter.

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

その他の回答 (1 件)

Venkat Siddarth Reddy
Venkat Siddarth Reddy 2024 年 5 月 22 日
編集済み: Venkat Siddarth Reddy 2024 年 5 月 22 日
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])
ans = 2x1 cell array
{[0.3500 0.7000]} {[ 0.4000]}
%Similarly for FrictionAngle
dataTable.FrictionAngle([1 2])
ans = 2x1 cell array
{[35 70]} {[ 40]}
Hope its clear

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by