Writing a script for multiple arrays with a set criteria for each array and identifying certain value locations
이전 댓글 표시
I am working with arrays of data, where each value is a latitude and longitude grid point - columns are longitude and rows are latitude.
There are three arrays of equal size, representing the same latitude-longitude grid points over the Earth. Each array however contains a different type of data: the first, temperature; the second, wind; the third, height of the atmosphere.
I want to develop a script which identifies certain grid points according to some criteria: The process:
- scanning the first array for if certain values are 20 units less than the surrounding grid points
- For these locations of where minimum values are, scanning the second array to check whether the value two places above it is negative.
- For these locations where the both the minimum values are (for the first array) and two places above is negative (for the second array), scanning the third array for where the value to the right of the location must be greater.
I presume this will require if statements and for loops.
For Example:
1st array
30 30 30 30 30 30 30 30
30 30 30 30 30 10 30 30
30 20 30 30 30 30 30 30
30 30 30 10 30 30 30 30
30 10 30 30 30 30 30 30
30 30 30 30 30 30 30 30
2nd array
22 22 22 22 22 22 22 22
22 22 22 -5 22 22 22 22
22 -5 22 22 22 22 22 22
22 22 22 22 22 22 22 22
22 22 22 22 22 22 22 22
22 22 22 22 22 22 22 22
3rd array
100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100
100 100 100 100 200 100 100 100
100 100 200 100 100 100 100 100
100 100 100 100 100 100 100 100
The script would scan array 1, find the values, scan array 2 at those values lcoations, if it matches critera, it scans array 3 at these lcoations, if it matches the criteria, creates a lsit of the row and column where the lcoations match all 3 criteria. for the above example it would be row and column ([r c]):
4 4
5 2
because in row 5, column 2:
1)10 is less than surrounding eight grid points, 2) the -5 two above it is negative and 3) the 200 is greater than 100.
Thanks for any help
댓글 수: 1
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2014년 10월 30일
편집: Andrei Bobrov
2014년 10월 30일
A = cat(3,[30 30 30 30 30 30 30 30
30 30 30 30 30 10 30 30
30 20 30 30 30 30 30 30
30 30 30 10 30 30 30 30
30 10 30 30 30 30 30 30
30 30 30 30 30 30 30 30],...
[22 22 22 22 22 22 22 22
22 22 22 -5 22 22 22 22
22 -5 22 22 22 22 22 22
22 22 22 22 22 22 22 22
22 22 22 22 22 22 22 22
22 22 22 22 22 22 22 22],...
[100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100
100 100 100 100 100 100 100 100
100 100 100 100 200 100 100 100
100 100 200 100 100 100 100 100
100 100 100 100 100 100 100 100]);
With Image Processing Toolbox
ii = imerode(A(:,:,1),[1 1 1;1 0 1;1 1 1]) > A(:,:,1) &...
imerode(A(:,:,2),[1;0;1;0;0]) < 0 &...
imdilate(A(:,:,3),[1,1,0]) > A(:,:,3);
[r,c] = find(ii);
Without Image Processing Toolbox
n = size(A);
f1 = false(1,n(2));
f2 = false(n(1),1);
l1 = [f1;diff(A(:,:,1))<0] & [flipud(diff(A(end:-1:1,:,1)))<0;f1] &...
[f2,diff(A(:,:,1),1,2)<0] & [fliplr(diff(A(:,end:-1:1,1),1,2))<0,f2];
l2 = sign(A(rem(n(1)-k +(0:n(1)-1),n(1))+1,:,2)) == -1;
l3 = [diff(A(:,:,3),1,2) > 0, f2];
[r,c] = find(l1 & l2 & l3);
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!