フィルターのクリア

How to build a set of matrices using the for loop

2 ビュー (過去 30 日間)
Quantopic
Quantopic 2014 年 8 月 4 日
コメント済み: Andrea Vandin 2020 年 6 月 5 日
Hi all, I need for building a set of matrices using the for loop; Starting from the main matrix with dimension 9x9, I want to build 8 matrices with dimension 9x2 that have the first column equal to the one of the first matrix and the second column equal to the second, the third, ..., the nineth column of the main matrix. I used the following code, but it does not work for some reason:
for i=2:9
[NewMatrix(i)]=[MainMatrix(:,1),MainMatrix(:,i)];
end
Can someone explain me what is the error in this code? Thanks in advances

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 4 日
編集済み: Azzi Abdelmalek 2014 年 8 月 4 日
To store your 8 matrices, use cell array
for i=2:9
coint{i}=[MainMatrix(:,1),MainMatrix(:,i)];
end
celldisp(coint)
  2 件のコメント
Quantopic
Quantopic 2014 年 8 月 4 日
Thanks a lot Azzi!
Andrea Vandin
Andrea Vandin 2020 年 6 月 5 日
This does not create a set of matrices. This creates a list of matrices. Meaning that you might have replicas of the same matrix in each entry.
Just try initializing MainMatrix as: MainMatrix = ones(9,9);
All entries of coint will contain a copy of the same matrix.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by