making column of zero matrix equal to one based on another matrix
古いコメントを表示
Hi ,
I have a zero matrix (A) of size mxn where m in number of observation and n number of feature. I have another non zero matrix (B) of size (mx1) where numbers respresent column in matrix A which should be replaced by one.
How to do this ?
採用された回答
その他の回答 (1 件)
Image Analyst
2014 年 2 月 25 日
Did you try
A(:, B) = 1;
3 件のコメント
Sukuchha
2014 年 2 月 25 日
Image Analyst
2014 年 2 月 25 日
編集済み: Image Analyst
2014 年 2 月 25 日
I agree with Paul. You said any column number of A that shows up in B should have that entire column of A set to 1. For example:
A = randi(9, 5, 8) % Random integers
B = [1,3,7]; % Set columns 1, 3, and 7 to all 1's.
A(:, B) = 1
カテゴリ
ヘルプ センター および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!