How to overlap two grids (matrices) created with meshgrid
이전 댓글 표시
I've created two separate matrices using meshgrid:
clear all; clc;
dx = 2;
dy = 2;
bdyx_A = 0:dx:50;
bdyy_A = 0:dy:50;
bdyx_B = 20:dx:30;
bdyy_B = 20:dx:30;
[X_A,Y_A] = meshgrid(bdyx_A,bdyy_A);
[X_B,Y_B] = meshgrid(bdyx_B,bdyy_B);
% Calculate some parameter as a function of your x and y
Z_A = sqrt(X_A.^2 + Y_A.^2);
Z_B = 3.*sqrt(X_B.^2 + Y_B.^2);
% Next, reshape all of our matrices into vectors:
G_A = [reshape(X_A,size(X_A,1)*size(X_A,2),1)...
reshape(Y_A,size(Y_A,1)*size(Y_A,2),1)...
reshape(Z_A,size(Z_A,1)*size(Z_A,2),1)]
G_B = [reshape(X_B,size(X_B,1)*size(X_B,2),1)...
reshape(Y_B,size(Y_B,1)*size(Y_B,2),1)...
reshape(Z_B,size(Z_B,1)*size(Z_B,2),1)]
figure; hold all;
scatter(G_A(:,1), G_A(:,2), 100, G_A(:,3),'s', 'filled');
scatter(G_B(:,1), G_B(:,2), 100, G_B(:,3),'s', 'filled'); colorbar;
Therefore, (assuming the dx and dy and end points are lined up correctly) we can see how the coordinates of "B" are a subset of the coordinates of "A". I would like to edit the G_B matrix so that it includes all of the G_A coordinates, but has NaN values in the coordinates where B's data doesn't originally exist.
I would be happy to elaborate or restate my problem if it is unclear.
Thank you in advance!
채택된 답변
추가 답변 (1개)
Walter Roberson
2014년 1월 20일
Quick cheat: interp2() without extrapolation.
If the grids are exactly aligned then you could be much more efficient: create the NaN matrix, find() the index of min(bdyx_B) in bdyx_A, find the index of max(bdyx_B) in bdyx_A, and copy the smaller data into that range of indices
P = nan(size(G_B));
P(11:16, 11:16) = G_A;
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!