plot coordinates in the center of grid

4 visualizaciones (últimos 30 días)
Elysi Cochin
Elysi Cochin el 25 de Mzo. de 2019
Comentada: KSSV el 25 de Mzo. de 2019
xy = [
11.2871990000000 75.8008150000000
11.2826320000000 75.8033060000000
11.2648170000000 75.8115220000000
11.2871920000000 75.8003903000000
11.2923570000000 75.7983420000000
11.2977640000000 75.7954980000000
11.3013130000000 75.7923960000000
11.2921850000000 75.7644030000000
11.2870320000000 75.7816260000000
11.2796160000000 75.7842500000000
11.2590560000000 75.7914280000000
11.2482280000000 75.7990630000000
11.3098790000000 75.7839610000000
11.2834140000000 75.8196346000000
11.2905720000000 75.8230735000000
11.2485406000000 75.8097699000000
11.2910006000000 75.8299190000000
11.2806053000000 75.8195341000000
11.2769439000000 75.7705414000000
11.2710306000000 75.7763048000000
11.2684317000000 75.7778582000000
11.2435829000000 75.7665305000000
11.2595089000000 75.7782871000000];
i wanted to convert these cordinate values, so that the points get plotted in the center of the corresponding grids
two colours, one colour for the values in the xy variable, and the other colour for values not in the xy variable.
i wanted to shift the xlimit and ylimit to 10 rows and 10 columns.
like below

Respuesta aceptada

KSSV
KSSV el 25 de Mzo. de 2019
xy = [
11.2871990000000 75.8008150000000
11.2826320000000 75.8033060000000
11.2648170000000 75.8115220000000
11.2871920000000 75.8003903000000
11.2923570000000 75.7983420000000
11.2977640000000 75.7954980000000
11.3013130000000 75.7923960000000
11.2921850000000 75.7644030000000
11.2870320000000 75.7816260000000
11.2796160000000 75.7842500000000
11.2590560000000 75.7914280000000
11.2482280000000 75.7990630000000
11.3098790000000 75.7839610000000
11.2834140000000 75.8196346000000
11.2905720000000 75.8230735000000
11.2485406000000 75.8097699000000
11.2910006000000 75.8299190000000
11.2806053000000 75.8195341000000
11.2769439000000 75.7705414000000
11.2710306000000 75.7763048000000
11.2684317000000 75.7778582000000
11.2435829000000 75.7665305000000
11.2595089000000 75.7782871000000];
NX = 11 ; NY = 11 ;
xi = linspace(11.24,11.31,NX) ;
yi = linspace(75.76,75.83,NY) ;
[X,Y] = meshgrid(xi,yi) ;
x = X(:) ; y = Y(:) ;
nel = (NX-1)*(NY-1) ; % Number of elements in the surface
nnel = 4 ; % Number of nodes per element
nodes = zeros(nnel,nel) ; % Initialize nodal connectivity matrix
count = 0 ;
for i = 1:NX-1
for j = 1:NY-1
l = (j-1)*(NX)+i ;
count = count+1 ;
nodes(:,count) =[l l+1 l+NX+1 l+NX];
end
end
% GEt mid points of ach cell
xm = mean(x(nodes)) ;
ym = mean(y(nodes)) ;
% Get points closer to (xm,ym)
idx = knnsearch([xm ; ym]',xy) ;
% Plot
[X,Y] = meshgrid(1:11,1:11) ;
X = X(:) ; Y = Y(:) ;
Xm = mean(X(nodes)) ;
Ym = mean(Y(nodes)) ;
figure
hold on
plot(X(nodes),Y(nodes),'k') ;
plot(Xm(idx),Ym(idx),'Ob') % points which exist in xy
not_idx = setdiff(1:numel(Xm),idx) ;
plot(Xm(not_idx),Ym(not_idx),'Or') % points which exist in xy
untitled.bmp
  2 comentarios
Elysi Cochin
Elysi Cochin el 25 de Mzo. de 2019
That was exactly what i wanted, but what if i want to give xtick and ytick markings as [11.23, 76.l8, ...] such values - though not exactly same, atleast that range based on what we extended it to a 10 x 10 plot. How to give that?
KSSV
KSSV el 25 de Mzo. de 2019
That case use x and y. Don't use X and Y.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by