Create a matrix from a vector

1 回表示 (過去 30 日間)
luca
luca 2019 年 9 月 16 日
コメント済み: luca 2019 年 9 月 16 日
Given the matrix M
M = [6 15 11 2 4 7 3 1 13;
14 0 16 0 5 9 0 0 0;
0 0 17 0 8 12 0 0 0;
0 0 18 0 10 0 0 0 0;
0 0 19 0 0 0 0 0 0;
0 0 20 0 0 0 0 0 0]
and the vector V= [1 2 3 4 8 11 13 14 15 16 18 19];
I want to reconstruct the Matrix M with just the value in V, obtaing A
A = [0 15 11 2 4 0 3 1 13;
14 0 16 0 0 0 0 0 0;
0 0 0 0 8 0 0 0 0;
0 0 18 0 0 0 0 0 0;
0 0 19 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0];
May someone help me?

採用された回答

madhan ravi
madhan ravi 2019 年 9 月 16 日
A = ismember(M,V) .* M % Note: 14 should be in 1,1 not 2,1
  1 件のコメント
luca
luca 2019 年 9 月 16 日
yes it should be in 2,1

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by