Why indexing returns values from first two columns and not from the whole matrix?

3 vues (au cours des 30 derniers jours)
Zhou Ci
Zhou Ci le 28 Sep 2021
Commenté : Walter Roberson le 28 Sep 2021
Hi everyone,
I've matched a 2 column vector (containing lat lon values respectively) from text file with 2 variables (also containing lat lon values) in matrix form. Output of this is
lat_txt = tab.lat; % extract the column of latitude values 3798x1 double
lon_txt = tab.lon; % extract the column of longitude values 3798x1 double
lat_i = imresize(M_lat,[2030 1354],'bilinear'); %M_lat is 406x270. So, I've interpolate it.
lon_i = imresize(M_lon,[2030 1354],'bilinear'); %M_lon is 406x270. So, I've interpolate it.
% matched the values from text file with the lat_i and lon_i
mask = ismembertol(lat_txt, lat_i) & ismembertol(lon_txt, lon_i); % gives 3798x1 logical (all values are true)
Next I've to done indexing to find out the values in another matrix 'z' that contains integers (0,1,2,3,4).
Vol = z(mask); % z = 2030x1354
The problem is Vol just returns values from 1st and 2nd column of z. Data in z is attached. It's first column contains 0. So, Vol shows 3798x1 where 1st row till row 2030 all are 0, then it starts getting values from 2nd column and first row of z. Why it's like this? Any help would be greatly appreciated.
  2 commentaires
KSSV
KSSV le 28 Sep 2021
You need to use griddata. Read about this.
Zhou Ci
Zhou Ci le 28 Sep 2021
Means I should use griddata instead of imresize?

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 28 Sep 2021
your ismembertol is going to return something with the same number of elements as lat_txt (first operand) but then you try to use that mask to index the larger z that is size of lat_i
If you reverse the order of operands in ismembertol then you would get something the size of lat_i
  12 commentaires
Zhou Ci
Zhou Ci le 28 Sep 2021
I understand this. So, is there any other way to do this task? Means use the lat lon from text file and extract Radius values from hdf file?
Walter Roberson
Walter Roberson le 28 Sep 2021
If I recall correctly, you already rejected the use of interp2() for this problem, even though using it would make a lot of sense.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by