How to create a double array from a cell array

I want to convert this data into the image shown after
paths = ["path1";"path2";"path3"];
cellData = {1,2,3,4;5,6,7,8;9,10,11,12};
How do I do this?

4 件のコメント

Walter Roberson
Walter Roberson 2021 年 2 月 7 日
Using randi() perhaps?
None of the values you list in the first row of that 8144x5 cell appear anywhere in the output of the table at the top, so we have no idea where you are getting the data from.
Asim Shahzad
Asim Shahzad 2021 年 2 月 7 日
@Walter Roberson the first image is just to describe what format I want my data in. I want 'n' rows of [39, 375, 530, 259] type of data.
Siddharth Bhutiya
Siddharth Bhutiya 2021 年 2 月 8 日
Do all rows have the same number of columns in your cell array data ?
Asim Shahzad
Asim Shahzad 2021 年 2 月 8 日
@Siddharth Bhutiya yes they do.

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

 採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 13 日

0 投票

paths = ["path1";"path2";"path3"];
cellData = {1,2,3,4;5,6,7,8;9,10,11,12};
imageFilename = paths;
vehicle = cell2mat(cellData);
table(paths, vehicle)
ans = 3x2 table
paths vehicle _______ ___________________ "path1" 1 2 3 4 "path2" 5 6 7 8 "path3" 9 10 11 12
If you are going to put more than one group into the vehicle area, then instead
paths = ["path1";"path2";"path3"];
cellData = {1,2,3,4;5,6,7,8;9,10,11,12};
imageFilename = paths;
vehicle = num2cell(cell2mat(cellData),2);
table(paths, vehicle)
ans = 3x2 table
paths vehicle _______ ____________ "path1" {1×4 double} "path2" {1×4 double} "path3" {1×4 double}
you will not be able to get the actual numbers to display in that situation

その他の回答 (1 件)

David Hill
David Hill 2021 年 2 月 8 日

1 投票

Why not just:
cell2mat(yourCellarray);

8 件のコメント

Siddharth Bhutiya
Siddharth Bhutiya 2021 年 2 月 8 日
As David mentioned you can use cell2mat to convert your cell array to a double matrix and then use that multi-column double matrix as your table variable, something like this
paths = ["path1";"path2";"path3"];
cellData = {1,2,3;4,5,6;7,8,9};
dblData = cell2mat(cellData);
t = table(paths,dblData)
t =
3×2 table
paths dblData
_______ ___________
"path1" 1 2 3
"path2" 4 5 6
"path3" 7 8 9
Asim Shahzad
Asim Shahzad 2021 年 2 月 11 日
@David Hill @Siddharth Bhutiya this does not show up in the format that I have shown in my question. The first image. Your answer gives me this:
What I want is this (visual representation, not the actual data - the second column):
Walter Roberson
Walter Roberson 2021 年 2 月 11 日
編集済み: Walter Roberson 2021 年 2 月 13 日
Your input is an 8144 x 5 cell, with 5th column not shown.
Your required output is a table with file names in the first column. The second column has a mix of 2 x 4 and 1 x 4 numeric arrays.
You have not given us any indication of where the file names are coming from for the first column, and there is nothing in the first four columns of the cells in your input that would give us any grouping information to put multiple entries together for the second column of the table.
Furthermore, not even one of the values in the 8144 x 5 cells that you show, appears in the second column of the table, so we are not able to deduce any pattern.
There is only one possible conclusion:
You. Should. Just. Create. Random. Output.
Asim Shahzad
Asim Shahzad 2021 年 2 月 13 日
@Walter Roberson Ok let me simplify it further.
My input data is
paths = ["path1";"path2";"path3"];
cellData = {1,2,3,4;5,6,7,8;9,10,11,12};
My output should look like this
How do I achieve this?
Walter Roberson
Walter Roberson 2021 年 2 月 13 日
paths = ["path1";"path2";"path3"];
cellData = {1,2,3,4;5,6,7,8;9,10,11,12};
imageFilename = paths;
vehicle = cell2mat(cellData);
table(paths, vehicle)
ans = 3x2 table
paths vehicle _______ ___________________ "path1" 1 2 3 4 "path2" 5 6 7 8 "path3" 9 10 11 12
If you are going to put more than one group into the vehicle area, then instead
paths = ["path1";"path2";"path3"];
cellData = {1,2,3,4;5,6,7,8;9,10,11,12};
imageFilename = paths;
vehicle = num2cell(cell2mat(cellData),2);
table(paths, vehicle)
ans = 3x2 table
paths vehicle _______ ____________ "path1" {1×4 double} "path2" {1×4 double} "path3" {1×4 double}
you will not be able to get the actual numbers to display in that situation
Asim Shahzad
Asim Shahzad 2021 年 2 月 13 日
@Walter Roberson thanks for the help.
'you will not be able to get the actual numbers to display in that situation'
How is it being done in the image I shared then? Just curious.
Walter Roberson
Walter Roberson 2021 年 2 月 13 日
Perhaps Variable Browser shows them. The command window will not.
Asim Shahzad
Asim Shahzad 2021 年 2 月 13 日
編集済み: Asim Shahzad 2021 年 2 月 13 日
@Walter Roberson just checked. It does. Could you please post your comment as an answer so I can accept it? I'll edit my question with the updated images.

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

カテゴリ

製品

リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by