make matrix from other matrix ?

i wan to make matrix of double but when the input of matrix [1,1,1,1,2,2,2,3,...] and i want other matrix to be like this
[ 1 1 0 0
0 0 1 0
0 0 0 1
]
how to do it is where some way to make if statement on row and cell data with for loop and make other matrix depance on it?

3 件のコメント

KSSV
KSSV 2022 年 4 月 16 日
What are the conditions or creiteria or dependency on two matrices?
jumana eltrabelsi
jumana eltrabelsi 2022 年 4 月 16 日
if row == 6 on matrix 1
when
on matrix 2 :
the
[ 0
0
0
0
0
1]
make row(6) = 1 and other = 0 one colum 1
and so on!
Xinzhi Jiang
Xinzhi Jiang 2022 年 4 月 16 日
I'm not following what you are trying to do here. What do you mean by "if row == 6 on matrix 1"? As in "when M1(6) == 1"? And do you intend to make one M2 matrix every time you check an M1(i) element? More elaboration with another example of what you are trying to achieve would be helpful

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

回答 (1 件)

Jan
Jan 2022 年 4 月 16 日
編集済み: Jan 2022 年 4 月 16 日

0 投票

Maybe:
row = [1,1,1,1,2,2,2,3];
s1 = max(row);
s2 = numel(row);
M = zeros(s1, s2);
M(sub2ind([s1, s2], row, 1:s2)) = 1
M = 3×8
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1

カテゴリ

ヘルプ センター および File ExchangePerformance and Memory についてさらに検索

質問済み:

2022 年 4 月 16 日

編集済み:

Jan
2022 年 4 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by