Hi all. I have data matrixes x(15x16) and y(15x16). And I want to create new matrix z(15x16) by taking some columns of x and y. For example, 3-4-5-10-12-14-16th columns will be taken from x and others from y. Is it possible with loop?

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 23 日
編集済み: Azzi Abdelmalek 2016 年 4 月 23 日

0 投票

You don't need a loop
out=y
idx=[3 4 5 10 12 14 16]
out(:,idx)=x

3 件のコメント

jack star
jack star 2016 年 4 月 23 日
Tried it with these codes and It said: Subscripted assignment dimension mismatch.
y=zeros(15,16);
x=randn(15,16);
out=y
idx=[3 4 5 10 12 14 16]
out(:,idx)=x
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 23 日
Yes, there is a mistake in the last line
y=zeros(15,16);
x=randn(15,16);
out=y
idx=[3 4 5 10 12 14 16]
out(:,idx)=x(:,idx)
jack star
jack star 2016 年 4 月 23 日
Thanks.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by