필터 지우기
필터 지우기

Keep matrix structure after indexing

조회 수: 5 (최근 30일)
Carlotta Dentico
Carlotta Dentico 2023년 9월 13일
댓글: Stephen23 2023년 9월 14일
Hello,
I have a matrix temp with dimensions 609x881 and my logical index A with the same 609x881 dimension.
When I extract the temp value based on my index using this code
temp_idx = temp(A);
my result is the vector temp_idx with dimension 230x1.
Now, since my final goal is to produce a spatial plot if this data, how can I extract the temp value based on my index so that my final matrix temp_idx has the dimension 609x881 so that I have my temperature values where the index match and NaN's outside the index.
Hope the question is clear.
Please find attach .mat file of my variables
THANK YOU :)

채택된 답변

Stephen23
Stephen23 2023년 9월 13일
편집: Stephen23 2023년 9월 13일
out = nan(size(temp));
out(A) = temp(A);
Or
out = temp;
out(~A) = NaN;
  댓글 수: 8
Carlotta Dentico
Carlotta Dentico 2023년 9월 13일
it is a matrix
Stephen23
Stephen23 2023년 9월 14일
I will assume that pt_spatial_lev20 has size 609x881x372, and A has size 609x881x1.
out = pt_spatial_lev20;
idx = repmat(A,1,1,size(out,3));
out(~idx) = NaN;

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by