How to extract cell array data to numeric arrays or a single multidimensional array
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
smachieca
am 16 Feb. 2021
Kommentiert: smachieca
am 16 Feb. 2021
I'm working with 7 sets of data which I've imported into Matlab using the code below. Each cell in data contains a 1620x1869 array. I want to perform operations on each of these datasets, but I can't figure out how to extract the data into individual numeric arrays. Although the operations that I perform next are roughly the same for all sets, the data used for each is different which is why I'd like to extract the data first so that I can run functions individually. I have tried cell2mat but get the following error:
"Error using cell2mat (line 52). CELL2MAT does not support cell arrays containing cell arrays or objects."
Perhaps importanting my data into a cell array was appropriate, however I haven't figured out how to save the data to seperate numeric arrays in the for loop.
Thanks in advance for any help.
------------
for i=1:7
myfilename = sprintf('myfile%d.txt',i);
filename = fullfile('path',myfilename);
fid = fopen(filename,'r');
data{i} = table2cell(readtable(filename));
fid = fclose(fid);
end
0 Kommentare
Akzeptierte Antwort
Jon
am 16 Feb. 2021
If I understand correctly, you should be able to extract the kth individual array using something like:
A = data{k}
3 Kommentare
Jon
am 16 Feb. 2021
I also often struggle with the syntax to get what I want when working with cell arrays. Sometimes I find it helpful to just play around a little with a simple example in my command window until I get it working.
Here's a good explanation of it all: https://blogs.mathworks.com/loren/2006/06/21/cell-arrays-and-their-contents/
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!