I have some grid data stored in Excel file and I am trying to reformat them into grid data. Below is my code:
A = xlsread('Name.xlsx', 'Feb'); % 3 column data of Latitutde, Longitude, and Variable.
[X, Y] = meshgrid([2.5:5:357.5],[-76:4:80]);[m n] = size(X);for i=1:m; for j=1:n; if A( A(:,1)==Y(i,j), A(:,2)==X(i,j), 3) > 0; Z(i,j) = A( A(:,1)==Y(i,j), A(:,2)==X(i,j), 3); else Z(i,j) = NaN; end; endend;
I am getting an "Index exceeds matrix dimensions" error. Clearly, some of the search are not supposed to retrieve results. How do I program it, so that it will automatically assign an NaN value, when index exceeds matrix dimensions?
Thanks.
Best Answer