how to write values ​​to a vector and matrix by coordinates?

5 ビュー (過去 30 日間)
Lev Mihailov
Lev Mihailov 2020 年 1 月 31 日
コメント済み: Lev Mihailov 2020 年 1 月 31 日
Hello! With the 'find' command, I found the coordinates of all elements greater than 1, now I need to write them to the matrix and vector, how can I do this?
A=vector 1x1000
x=vector 1x1000
y=vector 1x1000
B=matrix 28x1000
idx=find(A>1);
idx=vector coordinates 1x25 [102 502 ...]
and now I need to get
x=vector 1x25
y=vector 1x25
B=matrix 28x25

採用された回答

Stephen23
Stephen23 2020 年 1 月 31 日
編集済み: Stephen23 2020 年 1 月 31 日
You don't need find, it is simpler and more efficient to use logical indexing:
idx = A>1;
x_new = x(idx);
y_new = y(idx);
B_new = B(:,idx);
  1 件のコメント
Lev Mihailov
Lev Mihailov 2020 年 1 月 31 日
The logical indices contain a true value outside of the array bounds.
Error in RawERT20 (line 618)
y_new = y(idx);
Here is an error

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by