How can I add zeros between elements of a matrix?
    25 ビュー (過去 30 日間)
  
       古いコメントを表示
    
I have a vector [1,2,3];
and I want to obtain [1,0,2,0,3,0];
How can this be achieved?
0 件のコメント
回答 (2 件)
  Stephen23
      
      
 2020 年 8 月 31 日
        >> A = [1,2,3];
Method one: indexing:
>> B = zeros(size(A).*[1,2]);
>> B(1:2:end) = A
B =
   1   0   2   0   3   0
Method two: reshape:
>> B = A;
>> B(2,:) = 0;
>> B = B(:).'
B =
   1   0   2   0   3   0
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


