Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Inserting label (with mxn values) to a graph same matrix dimension

Subject: Inserting label (with mxn values) to a graph same matrix dimension

From: Ali Y.

Date: 5 Feb, 2011 21:18:03

Message: 1 of 4

Hi,
I have tree matrix (x,y,label). The x and y define location parameters on a graph, and the third one suppose to be label for each location. I tried to insert that with "text" command, but gives error (Value must be a column or row vector).
Could you please help me to modify the following code:
Thanks in advance;

a=0; b=0;
u=90/10;
N=0:u:90;
r=Data(:,1:2); % r=[55 59;23 0;74 89;2 10;83 72;103 106]
[X Y]=size(r);
for j=1:Y;
     i=1:X;
     x(i,j)=a+(r(i)*(cosd(N(j))));
     y(i,j)=a+(r(i)*(sind(N(j))));
     label(i,j)=text(x(i,j),y(i,j),num2str(N(j)));
end;
plot(x,y,'o')
hold on
text(x,y,num2str(label))

Subject: Inserting label (with mxn values) to a graph same matrix dimension

From: Miroslav Balda

Date: 5 Feb, 2011 23:51:04

Message: 2 of 4

Hi Ali,
The code is wrong. You may not multiply matrices of different types. Your matrix 'r' is of the size [6,2] and the size of the vector N is [1,11]. It is the reason why MATLAB does not like it.
More over, you used two nested cycles 'for'. It is also bad practice, because MATLAB is matrix oriented language. The follwing code shows, how to solve a slightly modified example:

% Ali
%%%%%% 2011-02-05
a=0;
r=[55 59;23 0;74 89;2 10;83 72;103 106];
[m,n] = size(r);
N = (0:m-1)'*90/(m-1); % size N is [6,1]
xy = repmat(r,1,2).*[cosd(repmat(N,1,n)), sind(repmat(N,1,n))] + a;
plot(xy(:,1),xy(:,2),'ob', xy(:,3),xy(:,4),'*b')
text(xy(:,1),xy(:,2),num2str(N,' %3.0f'))
text(xy(:,3),xy(:,4),num2str(N,' %3.0f'))

May be that it will help you.
Best regards

Mira

Subject: Inserting label (with mxn values) to a graph same matrix dimension

From: Ali Y.

Date: 6 Feb, 2011 08:27:03

Message: 3 of 4

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <iiknp8$513$1@fred.mathworks.com>...
> Hi Ali,
> The code is wrong. You may not multiply matrices of different types. Your matrix 'r' is of the size [6,2] and the size of the vector N is [1,11]. It is the reason why MATLAB does not like it.
> More over, you used two nested cycles 'for'. It is also bad practice, because MATLAB is matrix oriented language. The follwing code shows, how to solve a slightly modified example:
>
> % Ali
> %%%%%% 2011-02-05
> a=0;
> r=[55 59;23 0;74 89;2 10;83 72;103 106];
> [m,n] = size(r);
> N = (0:m-1)'*90/(m-1); % size N is [6,1]
> xy = repmat(r,1,2).*[cosd(repmat(N,1,n)), sind(repmat(N,1,n))] + a;
> plot(xy(:,1),xy(:,2),'ob', xy(:,3),xy(:,4),'*b')
> text(xy(:,1),xy(:,2),num2str(N,' %3.0f'))
> text(xy(:,3),xy(:,4),num2str(N,' %3.0f'))
>
> May be that it will help you.
> Best regards
>
> Mira
Hi Mira,
tanks for your reply, and sorry for misleading. My bad.
The problem is that, x and y define the location on a polar coordinate plot and their range has to be between 0 and 180. Also, N's length has to be 11 in the range between 0 and 90; because it's the classification range. I used "circle" formula, because i want to have each individual class (N=i) on different radius of this circle. The code which i have written execute this, though i have identification problem with positions, so i want to label the locations.
Respectfully,
Ali

(0-180)
y N(0:90)
| /
| /
| /
| /
| /_____________x(0-180)

Subject: Inserting label (with mxn values) to a graph same matrix dimension

From: Miroslav Balda

Date: 6 Feb, 2011 10:24:04

Message: 4 of 4

Hi Ali,
Maybe that the following code is what you may use:

% Ali
%%%%%%%%% 2011-02-06
close all
a=0; b=0;
r=[55 59;23 0;74 89;2 10;83 72;103 106];
[m,n] = size(r);

fig(7); % in FEX: www.mathworks.com/matlabcentral/fileexchange/9035
Nd = (0:10)*9;
[R,N] = meshgrid(r(:),Nd);
X = R.*cosd(N) + a;
Y = R.*sind(N) + b;
plot(X,Y,'o')
axis square
grid
dx = get(gca,'XLim');
dx = (dx(2)-dx(1))/100; % 1% of x-axis to shift a text right
c45 = cosd(45);
text(r(:,1)*c45+dx,r(:,1)*c45,num2str(r(:,1)))
text(r(:,2)*c45+dx,r(:,2)*c45,num2str(r(:,2)))

Best regards
Mira

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us