LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-31-2008, 11:32 PM   #1
ufmale
Member
 
Registered: Feb 2007
Posts: 378

Rep: Reputation: 30
matlab legend help.


I guess i may find some help here.

I am trying to plot a 4 discrete value i put in a vector as follows,
x = [ 4 2 4 1]
y = [ 2 0 4 1]
t = 1:4;

I would like to have a discrete plot with line connect each point. so I plot it twice.

plot(t,x,'o',t,x,'-')
plot(t,y,'*',t,y,'-')

Now I have problem creating legend for these plots. Does anyone know how to create a legend for this plots?

I actually want a tick on the x-axis to be something like ['John','Jame','Max','Dan'] instead of [1 2 3 4]
Right now, i know how to do it in the GUI, but don't know how to do it from the command. Need some help here too.

Last edited by ufmale; 03-31-2008 at 11:35 PM.
 
Old 04-01-2008, 12:50 AM   #2
ufmale
Member
 
Registered: Feb 2007
Posts: 378

Original Poster
Rep: Reputation: 30
I found a solution,

plot(1:4,x,'-b<','linewidth',3)

Then legend will work
 
Old 04-01-2008, 01:23 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: OpenSUSE 12.1 CentOS 6.2
Posts: 9,005

Rep: Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349Reputation: 1349
Quote:
Originally Posted by ufmale View Post
I found a solution,

plot(1:4,x,'-b<','linewidth',3)

Then legend will work
Yes. You can combine line style, marker and color like this. Regarding your second question you have simply to change the xticklabels using the function set. First be sure you don't have any other unwanted tick:
Code:
set(gca,'xtick',[1:4])
this will strip out any intermediate value, like 1.5, 2.5 and so on. Then you have to substitute the current labels with yours:
Code:
set(gca,'xticklabel',{'John','Jame','Max','Dan'})
here I used a "cell array" (note the brackets) instead of a "character array", so I'm not forced to have strings of the same length and eventually include extra blank spaces. The above function accept "cell arrays" as well.
For any further detail, see
Code:
help set
help get
help gca
help cell
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Unix Recovery Legend LXer Syndicated Linux News 0 03-14-2008 11:50 AM
Matlab wwnexc Linux - Software 8 03-21-2006 01:43 AM
LXer: The Legend of Linksys (Enforcing FLOSS licenses) LXer Syndicated Linux News 0 01-02-2006 04:01 AM
"the legend of phil wodemoyo" rusty_slacker General 15 10-05-2005 10:46 AM
Terminal cmd for starting Matlab M-file editor without starting matlab fubzot Linux - Software 2 02-15-2005 06:49 AM


All times are GMT -5. The time now is 08:58 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration