MATLAB Answers

Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

0

plot coordinates in the center of grid

Elysi Cochin さんによって質問されました 2019 年 3 月 25 日
最新アクティビティ KSSV
さんによって コメントされました 2019 年 3 月 25 日
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

  0 件のコメント

サインイン to comment.

タグ

1 件の回答

KSSV
回答者: KSSV
2019 年 3 月 25 日
 採用された回答

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 件のコメント

Elysi Cochin 2019 年 3 月 25 日
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
2019 年 3 月 25 日
That case use x and y. Don't use X and Y.

サインイン to comment.



Translated by