File and array manipulation.

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

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 17일
how many array do you have? and what is the size of your result array?
Matt Fig
Matt Fig 2012년 8월 17일
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
John Fulton 2012년 8월 17일
Thanks for your quick response. There are 365 arrays. Each array is 216 x 104.
John Fulton
John Fulton 2012년 8월 17일
sorry, i'm very new to matlab. i read the array using xlsread(). the arrays are found in a single file and each element (say row1, col1)represents a value i'd like to manipulate in each of the 365 arrays. so, i'd like to add the element contained in row1, col1 from array 1 to row1, col1 in array 2. i tried using multidimensional array functions.

댓글을 달려면 로그인하십시오.

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 17일
편집: Azzi Abdelmalek 2012년 8월 17일

0 개 추천

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

John Fulton
John Fulton 2012년 8월 17일
Thanks for your quick response. There are 365 arrays. Each array is 216 x 104.
John Fulton
John Fulton 2012년 8월 17일
sorry, i'm very new to matlab. i read the array using xlsread(). the arrays are found in a single file and each element (say row1, col1)represents a value i'd like to manipulate in each of the 365 arrays. so, i'd like to add the element contained in row1, col1 from array 1 to row1, col1 in array 2. i tried using multidimensional array functions.
Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 17일
can you post your code readind xls file ?
if you wrote
num=xlsread('YourFileName')
can you tell us what are size of num?
John Fulton
John Fulton 2012년 8월 17일
xlsread('Netrech_2002.xlsx') ...i haven't developed code yet. the file is large. where do you prefer i post it?
Oleg Komarov
Oleg Komarov 2012년 8월 17일
We need to understand it's size. You don't need to post it.
Also, I understand you're manually importing 365 excel files?
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
John Fulton 2012년 8월 17일
I am reading one file that contains 365 arrays separated by a row. Each array contains 216 columns, and 104 rows.
n = 38325 = number of rows containing groundwater recharge values m = 216 = number of columns containing groundwater recharge values
John Fulton
John Fulton 2012년 8월 17일
this is what's returned. >> A=cell2mat(num) contents reference from a non-cell array object.
Error in cell2mat (line 43) cellclass = class(c{1});
Azzi Abdelmalek
Azzi Abdelmalek 2012년 8월 17일
편집: Azzi Abdelmalek 2012년 8월 17일
sorry, num is not a cell array,
i have updated an the answer
John Fulton
John Fulton 2012년 8월 17일
Thanks Azzi. It looks like my array has been reshaped. I have to run out for the day, but will run your new answer.

댓글을 달려면 로그인하십시오.

Andrei Bobrov
Andrei Bobrov 2012년 8월 17일

0 개 추천

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);

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

질문:

2012년 8월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by