How to arrange alternate cells of a column into two columns?
    5 次查看(过去 30 天)
  
       显示 更早的评论
    
Let's say the column matrix is:
A =
     2
     6
     7
     3
     8
     3
     2
     9
     7
     5
     4
     1
And I need to obtain final result as 
A =
     2     6
     7     3
     8     3
     2     9
     7     5
     4     1
Can I know the way to split in this way?
0 个评论
采纳的回答
  Florian Bidaud
      
 2023-8-16
        
      编辑:Florian Bidaud
      
 2023-8-16
  
      A = [2 6 7 3 8 3 2 9 7 5 4 1]'
B = [A(1:2:end) A(2:2:end)]
3 个评论
  Dyuman Joshi
      
      
 2023-8-16
				That depends on the size you want to arrange - 
%For a 2D array, define atleast one dimension
ncol = 2;
A = [2 6 7 3 8 3 2 9 7 5 4];
%Convert to column vector
A = A(:);
%Add required zeros
A = [A;zeros(1,rem(numel(A),ncol))];
B = reshape(A,ncol,[])'
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
			
	产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


