Using a selection structure to extract points of intersection between two arrays
34 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I have two 360x340 arrays called lat and long. I want to find all of the intersecting points where lat is between 5 and 60, and where long is between 309 and 343. My plan is to create a 360x340 array and assign all of the values that meet that criteria a value of 1, otherwise assign all other lat/long combinations a value of zero.
I started writing this:
lat = netcdf.getVar(ncfile,5);
long = netcdf.getVar(ncfile,6);
Array = zeros(360,340);
if 5<=lat<=60 & 308<=long<=343
want: assign those data points a value of 1
else want: assign those data points a value of 0
end
Can anyone help me figure out how to assign the correct data points either a 1 or 0, depending on whether it meets my criteria? Also I'm not sure if my original if statement will work. Feel free to offer suggestions if you see any problems with that too. Thanks in advance.
0 个评论
采纳的回答
dpb
2014-3-2
ix=iswithin(lat,5,60) & iswithin(long,308,343);
done. :)
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
In general I'd probably code it by putting the ranges into variables rather than in the actual statement so that it's simpler to edit them for different choices.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!