필터 지우기
필터 지우기

how to plot a 10*10 grid map and how to number the grid cells? (sample pic is attached here)

조회 수: 99 (최근 30일)
Guys, I am in learning phase of matlab. I don't know how to plot this type of grid? i knew plotting simple grids, but this one made me mad. Is it possible to make this kind of one? I attached the model of the grid. thanks guys

채택된 답변

Youssef  Khmou
Youssef Khmou 2014년 9월 18일
I have a model that i wrote already, try to compare it with Joseph's method.
[X,Y]=meshgrid(1:11);
figure; hold on;
plot(X,Y,'k');
plot(Y,X,'k');axis off
I=(rand(11));
surface(I);
h=linspace(0.5,1,64);
h=[h',h',h'];
set(gcf,'Colormap',h);
N=100:-1:1;q=1;
x=linspace(1.5,10.5,10);
y=linspace(1.5,10.5,10);
for n=1:10
for p=1:10
text(y(n)-.5,x(p),num2str(N(q)),'FontWeight','bold');
q=q+1;
end
end
  댓글 수: 2
dinesh tce
dinesh tce 2014년 9월 21일
thanks youssef,,,your coding is simple and i can understand easily...i have one question..if i like to make some grid in black& white color what i have to do?? i tried with colormap command but it gives entire figure as black

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Michael Haderlein
Michael Haderlein 2014년 9월 15일
I don't know what you mean with "plot this grid". Maybe something like this?
grid=reshape(0:99,10,10)';
figure, surf(grid)
  댓글 수: 2
dinesh tce
dinesh tce 2014년 9월 18일
thanks for your reply.. i like to create 10*10 grid with cells labelled in numbers.that's all
ANDREA DI MARTINO
ANDREA DI MARTINO 2021년 11월 4일
Hi, how I can create an undirected graph with grid=reshape(0:99,10,10)';?
I need to create a grid graph 10x10 with undirected edges.

댓글을 달려면 로그인하십시오.


Joseph Cheng
Joseph Cheng 2014년 9월 18일
편집: Joseph Cheng 2014년 9월 18일
you can use the text() to insert the grid labeling. here is an example. this is for labeling 1x1 pixels but it is scalable for larger grid sizes.
%something in the background
I = magic(10)
%generate where each text will go
[X Y]=meshgrid(1:10,1:10);
%create the list of text
string = mat2cell(num2str([1:10*10]'),ones(10*10,1));
%display the background
imagesc(I)
hold on
%insert the labels
text(Y(:)-.5,X(:)+.25,string,'HorizontalAlignment','left')
%calculte the grid lines
grid = .5:1:10.5;
grid1 = [grid;grid];
grid2 = repmat([.5;10.5],1,length(grid))
%plot the grid lines
plot(grid1,grid2,'k')
plot(grid2,grid1,'k')
  댓글 수: 4
dinesh tce
dinesh tce 2014년 9월 21일
thanks joseph... it was useful to me..going to try my own logic.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by