Good afternoon! I need your help as im new in matlab about solving my following issue:
I have a matrix ret [420x500]
I want to separate this matrix in 10 matrices of [420x50] each. Is there any code than can generate 10 different matrices of same size from the matrix ret[420x500]?
I need 10 equally sized matrices (the breakpoints should be the 10th, 20th, 30th,... , 90th percentiles). I.e., 10 matrices from a given matrix ret.
Thank you in advance!!!

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 13 日

0 投票

Use mat2cell()
M; % 420x500 matrix
M_parts = mat2cell(M, 420, 50*ones(1,10));
M_parts is a cell array. You can access it like this
M_parts{1}; % 1st 420x50 matrix
M_parts{2}; % 2nd 420x50 matrix
..
..
M_parts{10}; % 10th 420x50 matrix

7 件のコメント

Andreas S
Andreas S 2020 年 10 月 13 日
Thank you for your reply. In addition I would like to find the average of the the first row for each new matrices M_parts{1} M_parts{2} .. .. M_parts{10}
Ameer Hamza
Ameer Hamza 2020 年 10 月 13 日
You can use cellfun()
first_row_averages = cellfun(@(x) mean(x(1,:)), M_parts)
Andreas S
Andreas S 2020 年 10 月 13 日
Thank you again. And what if I want find the average for each raw for these matrices?
Ameer Hamza
Ameer Hamza 2020 年 10 月 14 日
Similar approach
first_row_averages = cellfun(@(x) mean(x, 2), M_parts)
Andreas S
Andreas S 2020 年 10 月 14 日
It looks like it works. But I have a problem as I need to classify and rewrite the columns of the first matrix ret(420x500) by their averages from the smallest average to the biggest one and then run the other codes. How could I classify the matrix ret(420x500)?
Ameer Hamza
Ameer Hamza 2020 年 10 月 14 日
Following sort column of ret from smalles to largest
[~, idx] = sort(mean(ret));
ret_sorted = ret(:, idx);
Andreas S
Andreas S 2020 年 10 月 14 日
Thank you very much for all of your help. I appreciate it a lot!!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

質問済み:

2020 年 10 月 13 日

コメント済み:

2020 年 10 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by