0
$\begingroup$

The following piece of code is from the great book "An Introduction to Programming and Numerical Methods in MATLAB" by S.R. Otto and J.P. Denier

x = 0:pi/20:pi;

n = length(x);

r = 1:n/7:n;

y = x.ˆ2+3;

plot(x,y,’b’,x(r),y(r),’r*’)

...

Code continues from here specifying x axis and y axis labels and so on. When I start to write the code in command window, as soon as I put the last round bracket for plot command, Matlab returns figure window with the plot, without me having a chance to insert x and y axis labels and so on. How do I get the plot with everything complete?

$\endgroup$
  • $\begingroup$ Once the figure has been created, you can add axis labels and stuff with commands like xlabel, etc. $\endgroup$ – littleO Oct 13 '18 at 8:11
  • $\begingroup$ I was wondering if I can get a plot once and with final appearance, however after the generation of the figure, adding title and label stuff is fine, thanks. $\endgroup$ – Ali Kıral Oct 13 '18 at 9:19
0
$\begingroup$

Matlab's documentation for the plot function contains the following code example:

figure
plot(x,y,'Color',[0,0.7,0.9])

title('2-D Line Plot')
xlabel('x')
ylabel('cos(5x)')

I believe this is the standard way to do it in Matlab --- axis labels, title, etc. are added with additional commands after calling the plot function.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.