How to Extract 2048 values containing the maximum value?

1 回表示 (過去 30 日間)
Elham
Elham 2022 年 6 月 28 日
回答済み: Voss 2022 年 6 月 28 日
Hi,
I have a file with total of 49,152 x1 values. I want to split them into ranges of 2048 values and extract the 2048 values that has the maximum number so I can plot the largest 2048 values. This is the code I have right now:
plot(A(1:2048))
hold on
for i = 1:(numel(A)/2048)-1
data_segment = A(1+2048*i: 2048*(i+1));
z{i}=sum(data_segment);
z=z';
plot(data_segment)
end
hold off
xlim([1,2048])
%%ivMax=index of max
[Vmax,ivMax]=max(A)
L=data_segment(ivMax/2048)
Vmax gives me the maximum value and ivMax tells me the index of where to find that value. I set L to find which set of 2048 values to find the max and got ~21. How can I extract the 21st 2048 values? Is there any easier way to do this?

採用された回答

Les Beckham
Les Beckham 2022 年 6 月 28 日
編集済み: Les Beckham 2022 年 6 月 28 日
Note that this plots the group that contains the maximum datapoint in all of the data. It does not "plot the largest 2048 values". It is difficult to tell from your question if that is what you really want or not. Or maybe, in the context of your data, it is the same thing (without access to your data it is impossible to tell).
A = rand(49152,1) * 100; % sample data
[Amax, imax] = max(A)
Amax = 99.9989
imax = 31210
groupsize = 2048;
start_index = floor(imax/groupsize) * groupsize
start_index = 30720
plot(A(start_index:(start_index + groupsize - 1)));
grid on
hold on
plot(imax - start_index, A(imax), 'r*'); % highlight the max datapoint
  1 件のコメント
Elham
Elham 2022 年 6 月 28 日
Yes I want to plot only the largest 2048 values. Here are the numbers.

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

その他の回答 (1 件)

Voss
Voss 2022 年 6 月 28 日
"I want to plot only the largest 2048 values"
A = readmatrix('Data2048.txt');
A = sort(A,'descend');
plot(A(1:2048))

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by