How to read values for the range between each maximum and each minimum from a large uneven data file?

1 回表示 (過去 30 日間)
Hi,
I have a data file with 11000 rows and 4 columns. I need to read all values (in all columns) for data between each maximum and each minimum of column 3. Integrate column 3 and column 4, and calculate the mean of column 2, for each range between the maximum and minimum of column 3. Do I make sense?? I am really unsure about how to start. I am using Matlab2015a. I have attached what I want to do as image. For rudimentary case I can do like shown on the right in figure. But it would take a decade to solve. Need help.
  2 件のコメント
KSSV
KSSV 2020 年 7 月 27 日
You want to do this by splitting at every sixth row?
Madan Kumar
Madan Kumar 2020 年 7 月 27 日
No, the data is uneven. some times it's 5 rows, sometimes 6 rows and so on..

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

採用された回答

per isakson
per isakson 2020 年 7 月 27 日
編集済み: per isakson 2020 年 7 月 27 日
"range between the maximum and minimum of column 3" with a bit of guessing my interpretation is implemented in ixb and ixe
%%
fid = fopen('axn.txt','r');
cac = textscan( fid, '%f%f%f%f', 'CollectOutput',true );
num = cac{1};
[~] = fclose( fid );
%%
ixb = [ 1; find(diff(num(:,3))>0)+1 ]; % beginning of section
ixe = [ ixb(2:end)+1; size(num,1) ]; % end of section
%%
len = length( ixb );
result = nan( len, 2 );
for jj = 1 : len
result(jj,1) = mean(num(ixb(jj):ixe(jj),2));
result(jj,2) = trapz(num(ixb(jj):ixe(jj),3),num(ixb(jj):ixe(jj),4));
end
outputs
>> result
result =
51.494 -10.433
51.472 -23.332
51.479 -0.95127
51.463 -29.865
>>
  3 件のコメント
per isakson
per isakson 2020 年 7 月 27 日
編集済み: per isakson 2020 年 7 月 28 日
Is this better?
>> result
result =
51.492 -24.937
51.463 -29.865
51.472 -24.485
51.463 -29.865
>>
My mistake. Replace
ixe = [ ixb(2:end)+1; size(num,1) ];
by
ixe = [ ixb(2:end)-1; size(num,1) ];
with a minus one, not plus.
Now the beginings and ends of the "sections" agree with my intention
>> ixb', ixe'
ans =
1 6 12 18
ans =
5 11 17 23
>>

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by