How to insert copies of columns inside matrix with a specific condition?

1 回表示 (過去 30 日間)
Zuha Yousuf
Zuha Yousuf 2020 年 3 月 19 日
コメント済み: Zuha Yousuf 2020 年 3 月 19 日
So I have a matrix, lets call it A. A has 10 rows and 25 columns. I want to create 10 copies of each column, and insert those copies right after that column, and preceding the next column. Something like this:
[column 1 copy 1 copy 2 copy 3.........copy 10 column 2 copy 1...and so on until column 25]
Is there any way for me to do this in MATLAB? Any help appreciated!!!!

採用された回答

Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 19 日
Hi Zuha,
You can use reshape and repmat functions to do this.
Ar = repmat(A,10,1);
out = reshape(Ar,10,[]);
Hope this helps.
Regards,
Sriram
  3 件のコメント
Sriram Tadavarty
Sriram Tadavarty 2020 年 3 月 19 日
Hi Zuha,
Did you use even the reshape function?
When i sued both, i exactly get what you are looking for.
A = rand(10,25); % Size 10 x 25
Ar = repmat(A,11,1); % size 110 x 25 (For 10 copies use, 10+1 here)
out = reshape(Ar,10,[]); % Size 10 x 275
Attached the small image, to show this.
Regards,
Sriram
Zuha Yousuf
Zuha Yousuf 2020 年 3 月 19 日
Okay that worked! Thanks so much :)

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

その他の回答 (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