How can I put the output of each iteration into one table to find averages of each row later?
조회 수: 1 (최근 30일)
이전 댓글 표시
Here is the code I have used to loop through and process all files within a directory. It produces a graph of all of the iterations, but outputs each iteration as a separate command in the command window. Instead, I would like to add the results of each iteration into a table so that I can collate the data and find the average of each row later on. I have tried using zeros() but this distorts the data in the graph so it only shows one iteration output.
%%import folder location
path='file path';
fil=fullfile(path,'area*.txt');
d=dir(fil);
for k=1:numel(d)
filename=fullfile(path,d(k).name);
delim=';';
headings=6;
A=importdata(filename, delim, headings);
data=A.data;
variable1=data(:,1);
variable2=data(:,2);
%find minimum and maximum
%minimum
%isolate bottom 0.5 percentile
minimum=prctile(variable1, 0.5);
%maximum
maximum=prctile(variable1, 99.5);
%normalise data
normalised(k)=(variable1(k)-minimum)/(maximum-minimum);
%smooth graph
a=linspace(0,1,100);
b=spline(normalised, variable2, x);
%plot distribution figure 1
figure(1)
plot(a,b,'.-');
hold on
end
hold off
댓글 수: 0
채택된 답변
Bob Thompson
2019년 6월 18일
The simplest way to do this is to index b.
b(:,k) = spline(normalised_IQ, number_count, x);
% and then down in the plot section
plot(a,b(:,k),'.-')
I think that should take care of what you are looking for with regards to the storage.
Taking the averages of each column should be done outside the loop. Just add the following after the loop.
aves = mean(b,1);
댓글 수: 2
Bob Thompson
2019년 6월 18일
편집: Bob Thompson
2019년 6월 18일
The key part of what I did is on the left side of the equal sign, so the basic concept is the same. If you are looking to put two columns in at once then I would expect it to look something like the following:
% Single command format
b(:,2*k-1:2*k) = [number_count, normalised_IQ];
% Double command format; Choose only the above single or the below double
b(:,2*k-1) = number_count;
b(:,2*k) = normalized_IQ;
This may not be exactly what you're looking for, but it should be a rough idea.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!