MATLAB Answers

Using if and of two columns to find the value in another column

1 view (last 30 days)
Joe Sheckles
Joe Sheckles on 22 Feb 2020
Commented: Joe Sheckles on 24 Feb 2020
I have a shape file. I cannot attach it since it is too large.
But I used the code to read as:
S = shaperead('conus_20160101_24h.grb-var0.shp')
Now, I am able to get my table.
There are five columns: "Fields", "Geometry", "X", "Y", "value", "datetime"
What I need is to find "value" based on "X" and "Y"
For instance, if X is between 78 and 79 and Y is between, 48 and 49, read the value in "Value".
Thanks,
J

  0 Comments

Sign in to comment.

Accepted Answer

Matt J
Matt J on 22 Feb 2020
Here, I use T as the name of your table,
lookup=abs(T.X-78.5)<=0.5 & abs(T.Y-48.5)<=0.5;
T.Value(lookup),

  7 Comments

Show 4 older comments
Joe Sheckles
Joe Sheckles on 24 Feb 2020
I could not attach the R-sections - too large - even when compressed or doing 1:2.
I'm attaching a link. It also has the shapefile, m., mat.
Hope this works.
Thanks
Matt J
Matt J on 24 Feb 2020
So, one solution would be to convert R1 to a table, and then use the steps I originally proposed, e.g.,
S=struct2table(R1);
S.X=-S.X; %for some reason all X were negative
lookup=abs(S.X-73.9668)<=1 & abs(S.Y-40.7995)<=1;
values = S.value(lookup);

Sign in to comment.

More Answers (0)

Sign in to answer this question.