Sizing array to add to a 3D array

Aloha!
I have a relatively big array (sorted_celldata) with all my data (12 columns, 248976 rows), its contains data from the follow up of 23819 cells through the time.
I would like to simplify the access to the data by generating an array for each single cell (the id of each cell in in column 12 of sorted_celldata), and then store them in a 3 dimension array.
Here my code:
for p=1:max(sorted_celldata(:,12))
cell_idxlist = find (sorted_celldata(:,12) == p); % to look in which line I have data from cell p
celldata = sorted_celldata (cell_idxlist,:); % to generate a array with all data from cell p
nb_of_rows = size (celldata,1); % I put this line because of the error message below, trying to adjust the since of the arrays
nb_of_columns = size (celldata,2); % I put this line because of the error message below, trying to adjust the since of the arrays
celldata_arrays (nb_of_rows,nb_of_columns,p) = [celldata]; % here I generate my 3 dimension arrays, where each 3rd dimension is an array containing the data of a specific cell
end
Unfortunately, here the error message that I get:
Unable to perform assignment because the indices on the left side are not
compatible with the size of the right side.
Error in untitled9 (line 6)
celldata_arrays (nb_of_rows,nb_of_columns,p) = [celldata]

 Accepted Answer

You are changing the array size which is not how you do to store something. You are trying to store multi-dimensional array in a single field, that's why you are getting that error.
Choice 1:
% Change this line
celldata_arrays (nb_of_rows,nb_of_columns,p) = [celldata];
% to
celldata_arrays (nb_of_rows,nb_of_columns,p) = 0;
celldata_arrays (:,:,p) = celldata;
This way you will have empty fields whenever nb_rows and nb_columns is greater than previous values.
Choice 2:
celldata_arrays {p,1} = celldata;
Hope this helps.

4 Comments

Thanks Sudheer,
I put this code now:
for p=1:max(sorted_celldata(:,12))
cell_idxlist = find (sorted_celldata(:,12) == p);
celldata = sorted_celldata (cell_idxlist,:);
nb_of_rows = size (celldata,1)
nb_of_columns = size (celldata,2)
celldata_arrays (nb_of_rows,nb_of_columns,p) = 0;
celldata_arrays (:,:,p) = celldata;
end
It's going 1 for loop correctly, but I got an error for the second loop (since size of the second array is different... If I understand correctlu-y, it should have put 0 on the empty fields):
"Unable to perform assignment because the size of the left side is 100-by-12 and
the size of the right side is 75-by-12.
Error in untitled9 (line 11)
celldata_arrays (:,:,p) = celldata; "
Since I can have a maximum of 120 rows, I wrote this code:
for p=1:max(sorted_celldata(:,12))
cell_idxlist = find (sorted_celldata(:,12) == p);
celldata = sorted_celldata (cell_idxlist,:);
celldata_arrays (120,12,p) = 0;
celldata_arrays (:,:,p) = celldata;
end
But it does not even run through the first loop:
Unable to perform assignment because the size of the left side is 120-by-12 and
the size of the right side is 75-by-12.
Error in untitled9 (line 11)
celldata_arrays (:,:,p) = celldata;
Thanks for your precious help
I just try the second solution... and bigo, it's working just find!!!!
Thanks a lot for your help.
bigo , find??
sorry... "Bingo" (meaning "jackpot")
It's working perfectly, I could start the analyse... It's actually running... heating up my computer while it's already 34°C in the room (hot weather today!)

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!