Extract data in a single vector after a FOR cycle

Hello,
In the excel attached there are two columns of numerical data (113*85=9605 rows) I want to get the medium value for each row, and the maximum value every 85 rows. The final column vector (vect_max) of 113 elements has to contain the 113 biggest numbers. This script doesn't work properly, can you help me? Thank you!
clear
clc
numdata=xlsread('prova_matlab.xlsx');
media=mean(numdata,2);
vect_max=zeros(113,1);
for i=1:85:112*85
for j=1:113
blocco=media(i:84+i);
vect_max(j)=max(blocco)
end
end

 採用された回答

Fabio Freschi
Fabio Freschi 2019 年 9 月 4 日

0 投票

Ciao,
You can try to reshape your data, then apply max on the columns
media_reshape = reshape(media,85,113);
max_media = max(media_reshape,[],1);

6 件のコメント

Orazio Alberto Terracciano
Orazio Alberto Terracciano 2019 年 9 月 4 日
Thank you, it works!
If I want to extract also the pair of numbers in the excel whence every maximum value was obtained, how could I solve that?
I want to obtain a matrix composed of 113 rows and 2 columns.
Fabio Freschi
Fabio Freschi 2019 年 9 月 4 日
編集済み: Fabio Freschi 2019 年 9 月 4 日
The maximum is extracted from the mean value, so it shouldn't be found in the excel data numdata. Am I missing something?
Orazio Alberto Terracciano
Orazio Alberto Terracciano 2019 年 9 月 4 日
編集済み: Orazio Alberto Terracciano 2019 年 9 月 4 日
No, just the numbers of the excel which gave me the several maximum.
For example in the attachment I have underlined the first couple of values that gave me the first maximum (at row 39).
Orazio Alberto Terracciano
Orazio Alberto Terracciano 2019 年 9 月 4 日
I don't want the mean value, just extract the 2 numbers in the numdata for each maximum.
Fabio Freschi
Fabio Freschi 2019 年 9 月 4 日
you can extract the row of the maximum in the reshaped vector
[max_media, idx_max_loc] = max(media_reshape,[],1);
But these value must be translated by multiples of 85 to get the indices of the rows in the original vector, I mean, the first entry in idx_max_loc have to be multiplied by 85*0, the second for 85*1 and so on
idx_max_glo = (0:112).*85+idx_max_loc
The matrix you want is
max_data = numdata(idx_max_glo,:)
Orazio Alberto Terracciano
Orazio Alberto Terracciano 2019 年 9 月 4 日
perfect, thank you very much!!

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

その他の回答 (0 件)

製品

リリース

R2016a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by