現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Dimensions of arrays being concatenated are not consistent.
9 ビュー (過去 30 日間)
古いコメントを表示
hi, i receive this error...How can i solve it?
arr = load('matlab_bb.mat')
arr = struct with fields:
bb: {76x1 cell}
disp(arr.bb)
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Mini' }
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
{'On Micro'}
cell2mat(arr.bb)
Error using cat
Dimensions of arrays being concatenated are not consistent.
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
cell2mat(bb)
Error using cat
Dimensions of arrays being concatenated are not consistent.
13 件のコメント
Dyuman Joshi
2024 年 4 月 10 日
"How can i solve it?"
That depends on what you want to do with the data.
Stephen23
2024 年 4 月 10 日
You are trying to vertically concatenate character vectors which have different lengths. Of course that throws an error.
"How can i solve it?"
What exactly is there to "solve" ? What do you expect the output to be?
Luca Re
2024 年 4 月 10 日
編集済み: Luca Re
2024 年 4 月 10 日
So I created a structure made with cells... in this structure I inserted numbers and strings I have to load the .list file into another matlab app (closed source) but it gives me this error:" Error using cell2mat All contents of the input cell array must be of the same data type". So I should convert my structure so that the "cell2mat" works correctly for me
Luca Re
2024 年 4 月 10 日
Look this :
gg1=load('matlanb_gg1.mat');
Error using load
Unable to find file or directory 'matlanb_gg1.mat'.
Unable to find file or directory 'matlanb_gg1.mat'.
gg2=load('matlanb_gg2.mat');
gg1
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
gg2
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
{[1]}
are equals but :
>> cell2mat(gg_1)
Error using cell2mat
All contents of the input cell array must be of the same data type.
cell2mat(gg_2)
ans =
1
1
1
1
are equal but have different behaviors
Voss
2024 年 4 月 10 日
編集済み: Voss
2024 年 4 月 10 日
gg1 = load('matlab_gg1.mat').gg_1;
gg2 = load('matlab_gg2.mat').gg_2;
They are not equal:
isequal(gg1,gg2)
ans = logical
0
For one thing, they are different sizes:
whos gg*
Name Size Bytes Class Attributes
gg1 76x1 8001 cell
gg2 112x1 12544 cell
Also, cell array gg2 contains only double (numeric) arrays:
unique(cellfun(@class,gg2,'UniformOutput',false))
ans = 1x1 cell array
{'double'}
but some cell(s) in cell array gg1 contain a logical array:
unique(cellfun(@class,gg1,'UniformOutput',false))
ans = 2x1 cell array
{'double' }
{'logical'}
That's why you cannot use cell2mat on gg1. Recall the error message: All contents of the input cell array must be of the same data type.
Luca Re
2024 年 4 月 10 日
okk excsue me for different size ...I messed up with the data export
but about type data i see
Name Size Bytes Class Attributes
gg1 76x1 8001 cell
gg2 112x1 12544 cell
how do you see that one is double and the other is logical?
Voss
2024 年 4 月 10 日
編集済み: Voss
2024 年 4 月 10 日
"how do you see that one is double and the other is logical?"
They are both cell arrays, but some cells of gg1 contain a logical array (and some contain a numeric (double) array), whereas all cells of gg2 contain a numeric (double) array.
To see that, I used the class function. Specifically, I used cellfun to call class on each cell's contents, to get the data type of each cell's contents:
cellfun(@class,gg1,'UniformOutput',false)
and then took only the unique set of data types contained in the cell array:
unique(cellfun(@class,gg1,'UniformOutput',false))
Stephen23
2024 年 4 月 10 日
編集済み: Stephen23
2024 年 4 月 10 日
"how do you see that one is double and the other is logical?"
A cell array is not a double nor a logical. A cell array is a cell array.
Cell arrays are container arrays: they contain other arrays. They can contain double, logical, and other array types.
Voss's comment showed you exactly how they checked the content of those two cell arrays. Read their comment again.
Luca Re
2024 年 4 月 10 日
>> class(gg1(1))
ans =
'cell'
>> cellfun(@class,gg1(1),'UniformOutput',false)
ans =
1×1 cell array
{'double'}
but why with class i get 'cell' and cellfun i get 'double' ?
Stephen23
2024 年 4 月 10 日
編集済み: Stephen23
2024 年 4 月 10 日
"but why with class i get 'cell' and cellfun i get 'double' ?"
Because indexing a cell array using parentheses returns another cell array, NOT its content:
Exactly as the documentation states, use curly braces if you want to access the content of a cell array:
class(gg1{1})
% ^ ^ curly braces to access cell CONTENT
By the way, in MATLAB indexing using parentheses always returns an array of the same type, never the content. For container classes (e.g. cell, string, table) curly braces refers to the content. Simple and consistent.
Image Analyst
2024 年 4 月 10 日
@Luca Re see the FAQ for a good explanation of a cell array:
It explains how and when to use curly braces, square bracket, or round parentheses. I think it will help you get a good intuitive feel for when to use each.
回答 (1 件)
Ramtej
2024 年 4 月 10 日
Hi,
Assuming you are triying to convert cell array of characters into string array.
You can use "string" function for your case as shown below.
stringMatrix = string(arr.bb)
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)