How to get the exact lat lon position of nc file data
3 ビュー (過去 30 日間)
古いコメントを表示
Hi Folks
Thanks in advance
I could get the indexed position of the rows and columns of max / index value data with the below code
maxval=max(data(:));
[xmax,ymax]=find(data==maxval);
[ii,jj]=find(data >= 0 & data < 2);
but I need only the exact x and y location coordinates
I have classify the pixel values range according to my requirement as below
idx = data >= 0 & data< 2 ;
pix1 = data(idx);
idx = data >= 2 & data < 4 ;
pix2 = data(idx) ;
idx = iwant >= 4 & iwant < 6 ;
pix3 = data(idx) ;
idx = data >= 6 & data < 8 ;
pix4 = data(idx) ;
idx = data >= 8 & data < 10;
pix5 = data(idx);
idx = data >= 10 & data < 15 ;
pix6 = data(idx) ;
idx = data >= 15 & data < 20 ;
pix7 = data(idx) ;
idx= data >= 20 & data < 95;
pix8 = data(idx);
please find the atached data and lat, lon position
Kindly help
0 件のコメント
回答 (1 件)
ag
2025 年 1 月 29 日 8:24
To extract the exact x and y coordinates of pixels that fall within specific value ranges in a matrix, you can modify your approach slightly. Instead of just extracting the pixel values, you need to also find their corresponding indices.
Below is a modified version of your code with explainatory comments:
% Example data matrix
data = randi([0, 100], 10, 10); % Replace with your actual data
% Initialize cell arrays to store coordinates
coordinates = cell(8, 1);
% Define ranges and find indices for each range
ranges = [0 2; 2 4; 4 6; 6 8; 8 10; 10 15; 15 20; 20 95];
for k = 1:size(ranges, 1)
% Get logical index for current range
idx = data >= ranges(k, 1) & data < ranges(k, 2);
% Find coordinates of pixels in this range
[x, y] = find(idx);
% Store coordinates in the cell array
coordinates{k} = [x, y];
end
% Display coordinates for each range
for k = 1:size(ranges, 1)
fprintf('Coordinates for range [%d, %d):\n', ranges(k, 1), ranges(k, 2));
disp(coordinates{k});
end
Hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cartesian Coordinate System Conversion についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!