

Subdomain = domain(1:400:end) % we will plot error bars at every 400th point P6 = plot(domain,g(domain), '-b', 'LineWidth',3) % plot a thick solid blue line P5 = plot(domain,f(domain), '-r', 'LineWidth',3) % plot a thick dashed red line f3 = figure( 'Color',) hold on % new figure with a white background

Let us also add error bars to one of the functions denoting one standard deviation of the dependent variable. We'll keep the functions and domain the same.

Lets try again but this time, we will plot each function in its own color, change the line widths and types, the tick marks, the range of the axes, the background color, the font size, and add labels, a title, and a legend. Not bad for a first attempt but there are a lot of improvements we could make. P4 = plot(domain,g(domain)) % plot the second function. Hold on % tell Matlab to add future plots to the same set of axes P3 = plot(domain,f(domain)) % plot f, w.r.t. G = 5*sin(x)+5 % create a second function of x, g(x) = 5*sin(x) + 5ĭomain = -pi:res:pi % the domain of x, (i.e. f = x.^2 % create a function of x, namely f(x) = x.^2 The hold on command tells Matlab to superimpose all the plots onto the same figure, rather than overwriting previous plots. Here we plot two functions on the same set of axes. We evaluate the function at every point along its domain and plot the resulting x,y pairs, connecting consecutive dots. Plotting functions (curves) is very similar to the data plotting we just performed. Xlabel( 'x') ylabel( 'y') title( 'this is the title') We can specify the axis range and labels as follows. % plot larger red circles with black edges 'MarkerFaceColor', 'r'. There are many different types of marker and line styles available. We have told Matlab to plot the data in X vs the data in y and to display a blue solid dot for each data point. X = 5*rand(100,1) y = rand*X + rand(100,1) % generate some synthetic data rand( 'twister',0) % seed the random number generator
#Title of subplot matlab how to#
Here we show how to plot some random 2d data. Plotting 1d probability density functions.
