Remove 2D array elements outside of a range
5 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am attempting to remove array elements that fall outside of specified ranges. The array I am working with is 199x199 (wmax), and there are subsequent 199x199 arrays that contain both longitudes (x_pts) and latitudes (y_pts).
Essentially I want to create a smaller array that only includes data within 2 given latitudes and longitudes. Whenever I try this, it returns an N x 1 array, but I am hoping for a 2D array to be returned.
wmax(x_pts>-103&x_pts<-100&y_pts>34.75&y_pts<36.5;
0 件のコメント
回答 (1 件)
Voss
2022 年 3 月 30 日
Try one of these two things, depending on whether x_pts corresponds to the rows or columns of wmax:
% if x_pts corresponds to the rows of wmax and y_pts is the columns:
wmax(x_pts>-103 & x_pts<-100, y_pts>34.75 & y_pts<36.5);
% if x_pts corresponds to the columns of wmax and y_pts is the rows:
wmax(y_pts>34.75 & y_pts<36.5, x_pts>-103 & x_pts<-100);
Example:
x_pts = 1:10;
y_pts = 102:109;
% x_pts goes with rows, y_pts goes with columns, in this case
wmax = randn(numel(x_pts),numel(y_pts))
wmax(x_pts>3 & x_pts<7, y_pts>105 & y_pts<108)
2 件のコメント
Voss
2022 年 5 月 28 日
Make sure you have the comma where you had an & before:
wmax(x_pts>-103 & x_pts<-100, y_pts>34.75 & y_pts<36.5);
% ^
If that's not the problem, then can you demonstrate it here, with an example? Either construct a small matrix along with two vectors to use for indexing into the matrix, or save your variables to a mat file and upload it (with the paperclip button).
参考
カテゴリ
Help Center および 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!