How to convert cell to matrix

7 ビュー (過去 30 日間)
Manuela Maria ALAMPI
Manuela Maria ALAMPI 2022 年 1 月 10 日
コメント済み: Matt J 2022 年 1 月 11 日
I have a 100001x2 cell. Each cell is 1x1.
How can I convert it to matrix? I've tried cell2mat but I can't make it work
  5 件のコメント
Matt J
Matt J 2022 年 1 月 10 日
The code you've shown does not produce a 100001x2 cell array. You should attach the cell array dirctly in a.mat file so that we can avoid the steps of generating it.
Image Analyst
Image Analyst 2022 年 1 月 10 日
ca = signal.textdata([6:end],[1,2]);
save('answers.mat', 'ca');
Then attach answers.mat with the paperclip icon.

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

採用された回答

Jon
Jon 2022 年 1 月 10 日
Side stepping the issue a little bit, I can read in your data file perfectly as numerical values and not use cell2mat at all using:
A = readmatrix('i1uss.txt','NumHeaderLines',5)
  3 件のコメント
Manuela Maria ALAMPI
Manuela Maria ALAMPI 2022 年 1 月 11 日
It works! Thank you so much
Matt J
Matt J 2022 年 1 月 11 日
@Manuela Maria ALAMPI since it worked, you should Accept-click the post.

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

その他の回答 (2 件)

Matt J
Matt J 2022 年 1 月 10 日
cell2mat should have worked
A=num2cell(rand(100001,2)); whos A
Name Size Bytes Class Attributes A 100001x2 22400224 cell
B=cell2mat(A); whos B
Name Size Bytes Class Attributes B 100001x2 1600016 double

Simon Chan
Simon Chan 2022 年 1 月 10 日
Try this, where A is your 100001x2 cell:
cell2mat(cellfun(@(x) x,A))
  1 件のコメント
Manuela Maria ALAMPI
Manuela Maria ALAMPI 2022 年 1 月 10 日
It doesn't work

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by