File and array manipulation.
Mostra commenti meno recenti
I have one file that contains multiple arrays of similar dimensions. How can I add the cells from each array to generate a single array of the same dimension that represents the mean or median value for each cell?
4 Commenti
Azzi Abdelmalek
il 17 Ago 2012
how many array do you have? and what is the size of your result array?
Matt Fig
il 17 Ago 2012
Just so we understand. Your array is a cell array, or a numerical array? You say
"How can I add the cells from each array"
but do you mean you want to add the elements from each array? In MATLAB a cell array is a particular thing, and if you don't have a cell array, you shouldn't refer to cells but instead to elements.
John Fulton
il 17 Ago 2012
John Fulton
il 17 Ago 2012
Risposte (2)
Azzi Abdelmalek
il 17 Ago 2012
Modificato: Azzi Abdelmalek
il 17 Ago 2012
A=xlsread('YourFileName');
[n,m]=size(A);
M=reshape(A,105,m,n/105), % now you array (105,216,365)
M(105,:,:)=[]; %eliminate the separating row
% the first matrix is M(:,:,1)
% the second is M(:,:,2)
% ...
11 Commenti
John Fulton
il 17 Ago 2012
John Fulton
il 17 Ago 2012
Azzi Abdelmalek
il 17 Ago 2012
can you post your code readind xls file ?
Azzi Abdelmalek
il 17 Ago 2012
if you wrote
num=xlsread('YourFileName')
can you tell us what are size of num?
John Fulton
il 17 Ago 2012
Oleg Komarov
il 17 Ago 2012
We need to understand it's size. You don't need to post it.
Also, I understand you're manually importing 365 excel files?
Azzi Abdelmalek
il 17 Ago 2012
you said that your file contains many arrays, but when you read it, you import just one cell array. do you mean that this cell array contains many array. to extract them we must know what is the size of this cell array, just do
num=xlsread('YourFileName')
[n,m]=size(num)
and tell us what are n and m
John Fulton
il 17 Ago 2012
John Fulton
il 17 Ago 2012
Azzi Abdelmalek
il 17 Ago 2012
Modificato: Azzi Abdelmalek
il 17 Ago 2012
sorry, num is not a cell array,
i have updated an the answer
John Fulton
il 17 Ago 2012
Andrei Bobrov
il 17 Ago 2012
Consider the matrices of the same size as the matrix a.
s = size(a);
k = whos;
n = find(strcmp({k.class},'double'));
m = {k.size};
t = {k(n(cellfun(@(x)isequal(x,s),m(n)))).name};
val = eval(['[',cell2mat(strcat(t,'(:);')),']']);
out = accumarray(repmat(fullfact(s),numel(t),1),val,[],@mean);
1 Commento
Oleg Komarov
il 17 Ago 2012
Sorry, but this is a nightmare.
Categorie
Scopri di più su Multidimensional Arrays in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!