• I have a 450*90 matrix of values
  • I want to sample the matrix at 100 random sample points
However, while my interp2 function runs without errors, my output results vector contains NaN values after the 90th index.
The code below results in me getting NaN for points after the 90th index of vals - why, and how do I correct it?
Shouldn't I be able to sample 1 point from the matrix, or 50, or 100, or 1000 points?
Code:
row_vect = 1:450;
col_vect = 1:90;
[X,Y] = meshgrid(col_vect, row_vect);
V = abs(rand(450,90));
Xq = row_vect(1:100);
Yq = randi(89, 1,100);
vals = interp2(X, Y, V, Xq', Yq');
Thanks

 채택된 답변

Torsten
Torsten 2015년 8월 26일

2 개 추천

You try to extrapolate in Y-direction.
Read the description part for interp2 under
and you'll see why you get NaN for Y-values greater 90.
Best wishes
Torsten.

댓글 수: 3

macdommy74
macdommy74 2015년 8월 26일
Thanks Torsten ....your answer is exactly correct for my question .... however, I made a mistake in my question.
I will edit my original question.
All Y values should be within 1-90.
Torsten
Torsten 2015년 8월 26일
Use
[X,Y] = meshgrid(row_vect, col_vect);
instead of
[X,Y] = meshgrid(col_vect, row_vect);
Best wishes
Torsten.
macdommy74
macdommy74 2015년 8월 26일
I think this worked - thanks a million!!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 26일

2 개 추천

Your problem is your X not your Y. max(X(:)) is 90 because your first argument to meshgrid() is col_vec which is 1:90

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2015년 8월 26일

댓글:

2015년 8월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by