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!