split matrix into multiple matrices with variable number of rows according to value of a column

4 ビュー (過去 30 日間)
Hi
I have a large mx2 matrix that i want to split into multpile mx2 matrices according the value of column 1. so lets say for values of [20,100[ of column 1 i want to create a seperate mx2 matrix. then for [100,500[ another one and so one. The numner of rows can change for the large matrix but i always want to create 5 smaller matrices according to the value of the first column. So the smaller matrices wil also have a different number of rows. I added an example of a matrix in excell. Can someone help me with this problem?
thanks in advance
  5 件のコメント
Stephen23
Stephen23 2020 年 4 月 16 日
"I hope this figure explains my problem? "
Not really. Your sample file has values in the first column that range from 20 to 2001: you have not explained the general rule/s for how you want to split up those values (or any other values that you might have) into five groups.
Sören Gevaert
Sören Gevaert 2020 年 4 月 16 日
Thanks for the answer. The figure above is just an example. so first i need to set the limits. So lets say for column1 the values from 20 to 100 wil be the first matrix. then the values from 100 to 500 will be the second matrix. But for each matrix i need to have the corresponding values of column2 like my figure above. So at the end the large matrix will be split into 5 matrixes according to the values of column1.
Thanks in advance!

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

回答 (1 件)

darova
darova 2020 年 4 月 16 日
Here is how i see the solution
S = importdata('Bspectrumgloei.xlsx');
A = S.data;
ind = [ 20 54 78 98 132 ];
A1 = cell(5,1);
for i = 1:length(ind)-1
ix1 = find(A(:,1)==ind(i), 1,'first');
ix2 = find(A(:,1)==ind(i+1), 1,'first');
A1{i} = A(ix1:ix2-1,:);
end
A1{end} = A(ix2+1:end,:);
  2 件のコメント
Sören Gevaert
Sören Gevaert 2020 年 4 月 16 日
Thanks for the answer. unfortunately its not quite the answer what i need as i get ix1 = 17, and ix2 = 24. So it just gives me the number of rows between 2 limits. also i dont quite understand the code. What i want is to make 5 new matrices from the large matrix so i get 5 new matrices with 2 colums. the number of rows depends on the limits from column 1 (freq). The values of the limits wil always be fixed but the number of rows can vary.
thanks in advance
darova
darova 2020 年 4 月 16 日
I think you need mat2cell as dpd suggested earlier
Just divide your matrix into 5 equal

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by