Replace values in a matrice

조회 수: 3 (최근 30일)
Miguel Albuquerque
Miguel Albuquerque 2022년 7월 17일
편집: Miguel Albuquerque 2022년 7월 19일
Hey guys, thanks in advance,
I have this range(matrix) that has 1 x 5600 values. After that I perform a calculation , and I get a distance_matrix, that has 1 x 400 values.
Range includes the values in distance_matrix
What I want to do, is find in range the indexes where the values of distance_matrix are, and replace them by RMC, but such as, range continues to have 1 x 5600 values.
How can I do that?

채택된 답변

dpb
dpb 2022년 7월 17일
편집: dpb 2022년 7월 17일
Seems you're going over and over the same plowed ground here...use logical addressing.
isR=isfinite(D);
R(isR)=RMC;
or
isD=ismember(R,D);
R(isD)=RMC;
  댓글 수: 5
dpb
dpb 2022년 7월 19일
Well, that doesn't match the computed values or you wouldn't have the mismatch in lengths...
The code put a NaN or Inf out of range and 0 at the origin; the calculation of whatever was over the values in range which are the finite elements -- makes no sense otherwise.
Miguel Albuquerque
Miguel Albuquerque 2022년 7월 19일
편집: Miguel Albuquerque 2022년 7월 19일
Look this is the way I managed to do, is not fully automatized, but It works for waht I want, i just sometimes need to replace the last line of code, Is there a way I could do this in a more automatic way?
isR=find(y_max);
y_cutted=y_max(isR);
[a,b]=intersect(range,y_cutted);
b=b.';
RMC2=RMC(:,184:255);
range(:,(254:325))=RMC2;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Write Unit Tests에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by