ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.