How can I convert an array to a matrix?

조회 수: 5 (최근 30일)
Abdullah Türk
Abdullah Türk 2023년 4월 5일
댓글: Abdullah Türk 2023년 4월 5일
Hi,
I have an array as follow:
A = [127 77 107 148 30];
I want to convert this array as follows:
B = [127 0;77 0;107 0;148 30]
I mean, I want to split A array unequally or equally.
How can I do this?
Thanks.
  댓글 수: 4
Image Analyst
Image Analyst 2023년 4월 5일
편집: Image Analyst 2023년 4월 5일
Are you going to specify the number of columns to put into each row, like
columnsPerRow = [1; 6];
or
columnsPerRow = [1; 4; 2];
??? Otherwise how would we know? Is this your homework? Sounds like it.
Abdullah Türk
Abdullah Türk 2023년 4월 5일
The number of columns to put into each row is always changing. I want to apply this as a rule.

댓글을 달려면 로그인하십시오.

답변 (1개)

Torsten
Torsten 2023년 4월 5일
이동: Torsten 2023년 4월 5일
Something like this ?
A = [127 77 107 148 30];
B = [A(1:end-2).',zeros(numel(A)-2,1);A(end-1:end)]
B = 4×2
127 0 77 0 107 0 148 30

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by