How can I convert an array to a matrix?

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 件のコメント

James Tursa
James Tursa 2023 年 4 月 5 日
What is the rule for when to insert a 0?
Abdullah Türk
Abdullah Türk 2023 年 4 月 5 日
There is any rule insert 0. My aim is only split the array equally or unequally. For example, I have an array as follow:
X = [100 126 35 84 39 139 90];
And, I split it as follows:
Y = [100;126 35 84 39 139 90];
I know that Y array is not work. So, Y array can be as follows:
Y = [100 0 0 0 0 0;126 35 84 39 139 90];
The important issue for me that split X array.
I mean, X array have 7 elements and I want to split it as 1 and 6 elements. Of course, 1 and 6 values can change. For example, they can be 1,4,2.
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 日

0 投票

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2015a

タグ

質問済み:

2023 年 4 月 5 日

コメント済み:

2023 年 4 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by