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

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

 Accepted Answer

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

Thanks but I get this response:
Error using -
Too many input arguments.
Error in ReadStageIV (line 2)
lookup=abs(S.X-73.9668)<=0.00005 & abs(S.Y-40.7995)<=0.00005;
I suggest attaching S in a .mat file so that we can work with it. I suspect, however, that it is not a table variable.
Okay. Let's see. Maybe I'll provide a little background. Overall, I am trying to find a precipitation value ("Value") for a longitude (X) latitude (Y) coordinate. And I have shape files for each day of the year for 2016.
When I input:
R1 = shaperead('conus_20160101_24h.grb-var0.shp')
A table, titled R1, appears in the work space. It says it is a "582,653x1 struct"
When I click on the table, a pop-out table appears with the values. I've copied the first five rows values on an excel sheet (attached).
So lets say I want to read the precipitation value of when X = -106.383 and Y = 26.623
How would I code that?
(I've also attached the matlab file)
Thanks,
J
Attach R1 in a .mat file so we can study what it contains. If R1 is too big to upload, then just attach a part of it.
Rsection=R1(1:10);
save attachment Rsection
Also, for clarity's sake, be mindful that a "table" in Matlab refers to a very specific type of variable:
A struct is also a very specific variable type, so if R1 is a struct, it is not a table.
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
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);
Yes. This works perfectly. Thanks!

Sign in to comment.

More Answers (0)

Categories

Asked:

on 22 Feb 2020

Commented:

on 24 Feb 2020

Community Treasure Hunt

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

Start Hunting!