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

조회 수: 4 (최근 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 CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by