Why indexing returns values from first two columns and not from the whole matrix?
2 views (last 30 days)
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.
Walter Roberson on 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