Data picking from grid
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have data in three column (x,y,z)
I want to pick the values of z in each grid ...
For exmaple, in fiure, the values of x are plotted coressponding to x,y. Then with a diffrenec of 1 we grided the plot.
I want to calculate the data points placed in each grid.

채택된 답변
0 개 추천
I have edited the code for your given points so that you can get the points for each grid.
x = -130.7:0.1:-129.7 ;
y = 45.6:0.1:46.3 ;
n = length(x) ;
m = length(y) ;
[X,Y] = meshgrid(x,y) ;
data = importdata("data.txt") ;
x = data(:,1) ; y = data(:,2) ; z = data(:,3) ;
% plot grid
plot(X,Y,'r',X',Y','r')
hold on
for i = 1:m-1
for j = 1:n-1
% Get the points of each grid
P = [X(i,j) Y(i,j) ;
X(i,j+1) Y(i,j+1) ;
X(i+1,j+1) Y(i+1,j+1) ;
X(i+1,j) Y(i+1,j)] ;
idx = inpolygon(x,y,P(:,1),P(:,2)) ;
iwant = [x(idx) y(idx) z(idx)] ;
plot(x(idx),y(idx),'.')
drawnow
end
end
댓글 수: 11
aa
2020년 9월 12일
Thank you very much . We are very close to the required result. But, I want to place a third parameter in x-y grid. How can i do so ...
KSSV
2020년 9월 12일
You need not to worry about the third parameter, you can use the indices obtained to print the third parameter. I have edited the answer to include the third parameter.
aa
2020년 9월 12일
Thank you let me try this in my data set. In the next phase, I want to get an output as the point in each grid point.
KSSV
2020년 9월 12일
You can also use inequalities to get the points lying inside the grid if you are not okay with inpolygon.
m = 4;
n = 4 ;
x = linspace(0,1,m) ;
y = linspace(0,1,n) ;
[X,Y] = meshgrid(x,y) ;
% Pick some random points
x = rand(100,1) ;
y = rand(100,1) ;
z = rand(100,1) ;
% Get points lying inside the grid/ square
P = [0 0 ;0.3333 0 ; 0.3333 0.3333 ;0. 0.3333] ;
idx = inpolygon(x,y,P(:,1),P(:,2)) ;
iwant = [x(idx) y(idx) z(idx)] ;
% Use ineqialities
idx1 = x >= min(P(:,1)) & x <= max(P(:,1)) ;
idy1 = y >= min(P(:,2)) & y <= max(P(:,2)) ;
idxy = idx1 & idy1 ;
% plot grid
plot(X,Y,'r',X',Y','r')
hold on
plot(x,y,'ok')
plot(x(idxy),y(idxy),'+b')
aa
2020년 9월 12일
Thanks let me share with you the data set that i want to process ...
The grid dimensions are
x = linspace(-130.7,0.1,-129.7 ) ;
y = linspace(45.6,0.1,46.3) ;
Now we have to place the coresspodning enteries of z in the grid of x-y.
One the values placed in each grid after that i have to apply further analysis for teh enteries of each grid point
KSSV
2020년 9월 12일
x = -130.7:0.1:-129.7 ;
y = 45.6:0.1:46.3 ;
[X,Y] = meshgrid(x,y) ;
And you can proceed as given in the answer above.
aa
2020년 9월 12일
I just apply your code and get this 

KSSV
2020년 9월 12일
Do you think the points given in P i.e polygon/ rectangle form a closed region? The code is correct it should work if you give all the details correct.
aa
2020년 9월 12일
Yes, the code is working perfectly, but one last thing is the calculation of "iwant" for each grid point. In case of manual calculation, I change the points of p for each grid.
KSSV
2020년 9월 12일
Edited the answer.
aa
2020년 9월 12일
Thank you this is really amazing and work perfectly, But if i want to get an output file of data points in each grid , how can this be possible.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Simulink에 대해 자세히 알아보기
태그
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
