How to Access and Rename Doubles that are Stored in a Large Cell

I have a Cell that is 1x193. Each of the 193 elements is a 500x100 double.
I need to be able to access every element in this cell and rename each double to be Data1, Data2, Data3, etc. such that I can perform means on the rows of Data1, Data2, etc.
Does anyone have suggestions for how to accomplish this?

2 comentarios

"Does anyone have suggestions for how to accomplish this? "
Use indexing.
Creating/accessing numbered variables would be entirely the wrong way to go about this:
Indexing is simple, neat, and very efficient. Using numbered variables is a sign that you are doing something wrong.
I did come across that link while looking into this, but I didn't have a good workaround for it.
I understand what you are saying, but I don't really know what syntax I should use to do accomplish this...

Iniciar sesión para comentar.

Respuestas (1)

You no need to rename every elecment(500x100 double) of the cell which leads much complications, you can perform your operation directly using command cellfun
result_mean = cellfun(@(x)mean(x, 2), cell_array, 'UniformOutput', false); % cell_array is your vartiable
You can access mean values of the data as
result_mean{1}, result_mean{2}..result_mean{193}; % for mean values of the each row of the double array

5 comentarios

Okay great, I think this helped me a lot!
Now I have a 1x193 cell where each element is a double that stores the mean row average of every previous cell. That is exactly what I need.
Now I have to take the first element of every double in that cell and average them all together.
Here is what I know I have to do:
Write a loop to access every double in this new results_mean cell.
Pull the first element from this double, the first element from the next double, the first element from the next double, etc and average those together.
This is the code I have so far:
result_mean = cellfun(@(x)mean(x, 2), dataStore, 'UniformOutput', false);
for i=1:193
arrayvalues = cellfun(@(x)mean(x, 2), result_mean, 'UniformOutput', false);
end
Any help would be appreciated.
"Any help would be appreciated."
Forget about cellfun, just concatenate your cell data into one numeric array, then call mean and use indexing as required. Fiddling around with that cell array is a red herring.
+1 Stephen
Okay.
So I need to convert my cell into a 3D array then?
dataStorage = cat(3, dataStore{:});
But, I still have to calculate the average of all of the first elements that were in my cells previously. Would that be something like:
rowAvg = squeeze(mean(dataStorage, 2));
or
rowAvg = mean(dataStorage,3)
Thanks for the help.
Do NOT use datastore as a variable name, it is the name of an important inbuilt function.
Where C is your cell array, calculate the mean of each row:
A = cat(3, C{:});
M = mean(A,2)
It will have size 500x1x193. Use indexing to access particular pages, or permute or reshape to rearrange those dimensions. Avoid squeeze.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

Pat
el 17 de Feb. de 2020

Comentada:

el 18 de Feb. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by