How to make multiple matrices from a single matrix with certain rows and columns?

1 回表示 (過去 30 日間)
Laliguras
Laliguras 2013 年 5 月 7 日
回答済み: Abhijeet 2023 年 2 月 10 日
Hi,
I have to split a large matrix in multiple submatrices with certain rows and columns. Here is how my matrix named 'test' looks like:
0 10 20 30 40
100 200 300 400 500
200 300 400 500 600
300 500 400 400 400
100 300 300 400 500
Now I need to split it into four matrices with file extension names carrying the first rows numbers (except 0) e.g. test_10, test_20, test_30, test_40 and submatrices as below: test_10 will have 2:5 rows and 1st and 2nd columns, test_20 will have 2:5 rows and 1st and third column, test_30 will have 2:5 rows and 1st and 4th columns and test_40 will have 2:5 rows and 1st and 5th columns. Thank you in advance and I really appreciate your help.

回答 (1 件)

Abhijeet
Abhijeet 2023 年 2 月 10 日
Please use the following code format to break matrix into multiple matrices :
matrix = [0 10 20 30 40; 100 200 300 400 500; 200 300 400 500 600; 300 500 400 400 400; 100 300 300 400 500];
test_10 = matrix(2:5, [1, 2]);
test_20 = matrix(2:5, [1, 3]);
test_30 = matrix(2:5, [1, 4]);
test_40 = matrix(2:5, [2, 5]
test_40 = 4×2
200 500 300 600 500 400 300 500
% A sample output of test_40 has been printed for reference

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by