How to find the maximum values from each column 2 and 3 and find the corresponding values from column 1?

조회 수: 4 (최근 30일)
I have 543 .txt files with 3 columns. I need to find the maximum values for column 2 and 3 for each of these files and scatter plot the values. Then I have to find corresponding values from column 1 for those maximum values in Column 2 and 3 and again scatter plot those values. Please help. This is the code I wrote.
list=dir('*.txt');
for n=1:length(list)
filename=list(n).name;
filename_edit=strrep(filename,'.',';');
part=textscan(filename_edit,'filename;%d;%d;%d;%d;%s');
delimiterIn = ' ';
A = importdata(filename,delimiterIn);
Altitude = A(:,1);
Digisonde = A(:,2);
COSMIC = A(:,3);
for i = 1:n
if Altitude > 150,
out1 = max(Digisonde);
out2 = max(COSMIC);
else
out3 = max(COSMIC);
end
end
scatter(out1,out2,'filled')
xlabel('Digisonde')
ylabel('COSMIC')
end
  댓글 수: 3
SGMukherjee
SGMukherjee 2018년 4월 16일
The values of out1 and out2 keep on being replaced by new values. But I need to scatter plot for all the maximum values of "COSMIC" and "Digisonde" from 543 files.
Jan
Jan 2018년 4월 16일
편집: Jan 2018년 4월 16일
You overwrite all values in both loops and each iteration. The purpose of the inner loop "for i=1:n" is not clear, because it calculates the same data n times. If you want to store the values, store them. An example:
r = zeros(1, 100);
for k = 1:100
r(k) = rand;
end
Now the elements of r are collected by storing each value in a new element of the vector r.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2018년 4월 16일
 find corresponding values from column 1 for those maximum values in
 Column 2 and 3

This would be:

   [out1, index1] = max(Digisonde);
   alt1           = Altitude(index1);
   [out2, index2] = max(COSMIC);
   alt2           = Altitude(index2);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by