assign values from logial vector to a new matrix with the same size
1 回表示 (過去 30 日間)
古いコメントを表示
function B = functionA(A)
B = zeros(size(A));
D= A>0;
B = A(D);
I want to assign the values of A that met the condition (>0) to a matrix B of the same size as A. I wand a matrix B with zeros, the same size as A and the values of matrix A. Does anyone has a hint how to do this?
0 件のコメント
回答 (2 件)
Arthur Goldsipe
2018 年 3 月 7 日
編集済み: Arthur Goldsipe
2018 年 3 月 8 日
You can use an indexing variable like D on both the left and right side of an assignment. If I understand your questions, you can get what you want by changing the last line of your sample code to the following:
B(D) = A(D);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!