Reza_M
Reza_M

Reputation: 439

Loading a saved cell array not as struct

I have one question related to loading cell array in Matlab. I have read the similar questions but none of them solve my problem! I have a cell array with size {400*350} in my workspace. I saved this cell array as usual:

save ('myoutput.mat','cell_array');

Then I tried to reload this mat file. I used:

3D_coordinates = load ('myoutput.mat');

when this mat file is loaded in my workspace it converted to a struct file with size 1*1. I have to click on it and inside of the structure file there is one cell. when I click on that cell my whole cell array is appeared! it means my whole cell array is in a cell inside of a structure variable! then I assumed that by converting structure to cell I could access to my whole array.

cell_array = struct2cell(3D_coordinates);

but nothing changed! my cell_array size still 1*1 and inside of it, there is on cell, when I click on that cell , whole my cell array will be appeared !!! I want to access to my whole cell array in my workspace directly like before saving! How can I do that?

Upvotes: 2

Views: 1613

Answers (1)

Robert Seifert
Robert Seifert

Reputation: 25232

Just do:

coordinates = load('myoutput.mat');
cell_array = coordinates.cell_array

where coordinates is the struct you get after loading the .mat-file and cell_array is the name of the included cell array.

Be aware that variable names in Matlab cannot start with a number!


You can save a line by using importdata instead of load and get directly to the cell array:

cell_array = importdata('myoutput.mat')

Upvotes: 3

Related Questions