i want to find average of arrays named H_1 ,.....H_n. code should be dynamic such that for example n= 82 then program should importdata from H_1 to H_82 and find their average
what is the mistake with this program I am unable to get this.
n=5;
for q=1:n
assignin('base',['T_',num2str(q)],importdata('Tfunct2_',num2str(q),'.mat','TFunct'));
T(1,n)=T_,num2str(q);
end
T_f=mean(T);

4 件のコメント

Amit
Amit 2014 年 11 月 21 日
n=5;
for q=1:n
eval(['Tfunct2_',num2str(q)])=importdata('Tfunct2_',num2str(q),'.mat');
assignin{'base','TF',eval(['Tfunct2_',num2str(q)])};
T(1,q)=TF;
end there is error in each line as shown by matlab bt in code which i wrote earlier following lines work properly as:
1. assignin('base', 'PClean',eval(['PClean_',num2str(ii)]));
2. T1=importdata('Tfunct2_1.mat','TFunct');
but as want to make a loop to import and take average of the arrays so i am writing this code.
Amit
Amit 2014 年 11 月 21 日
As i have very large number of Tfunct hence i am going for a loop.
Amit
Amit 2014 年 11 月 21 日
n=5;
for q=1:n
TF=importdata('Tfunct2_',num2str(q),'.mat');% import data to TF
T(1,q)=TF;% load TF in array T
end
T_f=mean(T); %Taking mean of T i.e. all TF from 1 TF1 to TF5
Julia
Julia 2014 年 11 月 21 日
What is the error message?
I do not know much about the functions you use for importing. Perhaps you should build the string before you use the import function.

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

 採用された回答

Julia
Julia 2014 年 11 月 21 日

0 投票

Hi,
you overwrite T(1,n) in each loop iteration.
You must replace either the 1 or the n with q.
I don't understand what you do with
T_,num2str(q)
Is the comma intended?

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

タグ

質問済み:

2014 年 11 月 21 日

コメント済み:

2014 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by