フィルターのクリア

Copy values from a vector to a matrix

4 ビュー (過去 30 日間)
sami elahj
sami elahj 2016 年 1 月 9 日
コメント済み: sami elahj 2016 年 1 月 9 日
i have a problem trying to replace (copy) values from a vector to a matrix. So given this matrix
1 1 1
1 1 1
1 1 1
0 0 1
0 0 1
0 0 1
the plan is to copy values from this vector V=[0;10;20;30;40;50;60;70;80;90;100;110;120] starting from 10 ,V(2), into columns of the above matrix , to obtain this:
10 40 70
20 50 180
30 60 190
0 0 100
0 0 110
0 0 120

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 1 月 9 日
sami - if
A = [1 1 1
1 1 1
1 1 1
0 0 1
0 0 1
0 0 1];
and
V = [0;10;20;30;40;50;60;70;80;90;100;110;120];
then try
A(A>0) = V(2:end);
In the above, A>0 returns a logical matrix of ones and zeros where a one indicates that the element of A is greater than zero (as per our condition) and zero indicates that the element of A is less than or equal to zero. A(A>0) is then just those non-zero elements of A. We then assign all of the non-zero values of V (so from index two onwards) to those elements of A that are non-zero.
  1 件のコメント
sami elahj
sami elahj 2016 年 1 月 9 日
Thank you very much

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by