how can I take the (x,y) coordinates of each point by having two different vectors for x and y respectively?

11 views (last 30 days)
Lets say that I have a matrix T=[1 2 1 2 3;1 2 4 1 2;0 2 1 3 4;2 1 0 3 1] I used the below code in order to have a plot
figure, axis([0 10 0 10]);
grid on; hold on;
[m,n] = size(T);
m = m*2 - 0.5;
n = n*2 - 0.5;
for i = 1:size(T,1)
I = (i-1)*2;
for j = 1:size(T,2)
J = (j-1)*2 + 0.5;
if(T(i,j)>0)
plot(J,m-I,'b.','MarkerFaceColor', 'b');
end
if(T(i,j)>1)
plot(J+1,m-I-1,'b.','MarkerFaceColor', 'b');
end
if(T(i,j)>2)
plot(J+1,m-I,'b.','MarkerFaceColor', 'b');
end
if(T(i,j)>3)
plot(J,m-I-1,'b.','MarkerFaceColor', 'b');
end
end
end
how can I take the (x,y) coordinates of each point from the plot by having two different vectors for x and y respectively?

Accepted Answer

Guillaume
Guillaume on 28 Jul 2015
With code like this you need to write a comment explaining what's going on: what the different values of T mean and how the point coordinates are calculated. You may know now what it is but when you revisit the code in a few months you'll have forgotten. And it helps anybody else understand what is going on.
One possible way to build your coordinate array:
[rows, cols] = size(T);
[basex, basey] = meshgrid(0.5:2:2*cols,rows*2-0.5:-2:0.5);
%when T > 0, use basex, basey
%when T > 1, also use basex+1, basey-1
%when T > 2, also use basex+1, basey
%when T > 3, also use basex, basey-1
x = [basex(T>0); basex(T>1)+1; basex(T>2)+1; basex(T>3)];
y = [basey(T>0); basey(T>1)-1; basey(T>2); basey(T>3)-1];
figure, axis([0 10 0 10]);
grid on; hold on;
plot(x, y, 'b.','MarkerFaceColor', 'b');

More Answers (0)

Categories

Find more on Data Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!