MATLAB Answers

0

I wish to do the following operation using nested 'for' loop. Can anybody help me to find the best solution preferably without using structure and functions.

Asked by Gyan Raj Koirala on 26 Apr 2016
Latest activity Commented on by Jon
on 26 Apr 2016
1. I have 120 '.asc' files, each having 19 rows and 200 columns, named as F1.asc, F2.asc and so on.
2. I wish to load all the files in matlab environment one at a time and store in a different variable name as File1.mat, File2.mat and so on.
3. From loaded .mat file I wish to add each respective elements from each row one at a time and average it and save to another file as Avg1.asc, Avg2.asc and so on.
I tried the code something like this but encounters series of errors. Can you please help me to overcome this issue:
for i=1:19 %for summation of all 19 rows
S=zeros(1,200) %for the summation of rows elements
for j=1:120 %for loading 120 files
F(j)=dlmread('F',num2str(i),'.asc'); %read 120 .asc files named F1.asc, %F2.asc and so on
A(j)=sum(F(j),S,[i,:]); %sum each elements from the particular row
end
Avg(i)=A(j)/120; %average each elements of first row individually from the %loaded 120 files
dlmwrite('Avg',num2str(i),'.asc',Avg(i)); %save each averaged file in '.asc' format
end
Thanks in advance.

  1 Comment

It would be of great help to us if you could post an example file and expected outcome.

Sign in to comment.

Tags

0 Answers