finding mean

1 回表示 (過去 30 日間)
FIR
FIR 2012 年 6 月 12 日
I have a 30 matrix of size 256x256 stored in in different variables,
for ex the variables are A,D,R,T,Y,......ETC,EACH variable has same matrix size,now i want to find mean for each matrix and store it s mean values in a separate variable ,please help

採用された回答

the cyclist
the cyclist 2012 年 6 月 12 日
It's pretty awkward if there is no pattern to the naming of the variables, so if you can fix the naming problem upstream, you should try to do that. If you can't, then one approach is to define a function that takes a variable number of arguments, and does the mean of each one:
function arrayOfMeans = getMeans(varargin)
arrayOfMeans = zeros(nargin,1);
for n=1:nargin
arrayOfMeans(n) = mean(varargin{n}(:)); % Calculating means of all elements in array
end
end
Then call that function with the list of your variables as the input. For example,
>> getMeans(magic(3),rand(7),eye(4))
In your case, you would do
>> getMeans(A,D,R,T)
etc

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 6 月 12 日
  1 件のコメント
FIR
FIR 2012 年 6 月 13 日
walter i have seen the link .but could not find a solution ,can u please tell how to get a solution as per my post posted above

サインインしてコメントする。


Andrei Bobrov
Andrei Bobrov 2012 年 6 月 13 日
a = whos;
b = strcat({a(cellfun(@(x)isequal(x,[256 256]),{a.size})).name},',');
AD_etc = eval(['{',[b{:}],'}']);
AD_mean = cellfun(@(x)mean(x(:)),AD_etc,'un',0);
out = cell2struct([AD_etc;AD_mean],{'data','mean'});

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by