Changing two variables in a for loop

3 ビュー (過去 30 日間)
KatherineS
KatherineS 2019 年 6 月 13 日
コメント済み: Alex Mcaulley 2019 年 6 月 13 日
Hi,
I would like to change two variables in a for loop. I have a matrix A and would like to create a new matrix that looks like:
A(1,1) 0 0 0 A(1,2) 0 0 0 A(1,3) ...
A(2,1) 0 0 0 A(2,2) 0 0 0 A(2,3) ....
Where the new matrix is 4 times as many coloums as the original matrix and the same number of rows (in the end 139 x 3774).
What is the best way to do this?
Thanks in advance for your help.

回答 (1 件)

Alex Mcaulley
Alex Mcaulley 2019 年 6 月 13 日
Try this:
B = zeros(size(A,1),4*size(A,2));
B(:,1:4:end) = A;
  2 件のコメント
KatherineS
KatherineS 2019 年 6 月 13 日
Thanks it worked!
Alex Mcaulley
Alex Mcaulley 2019 年 6 月 13 日
Please, accept the answer to close the question

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

カテゴリ

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