MATLAB: How to change the line width for fplot

figureMATLAB

Hello All,
I want to make lines in graph thicker. Here is my code, but it seems not working.
clear all;
close all
clc;
w1=0;
w2=16.73;
x1= @(t) 0.05*cos(w1.*t)-0.05*cos(w2.*t);
x2= @(t) 0.05*cos(w1.*t)+0.05*cos(w2.*t);
graph1 = plot(figure1);
set(graph1,'LineWidth',2);
fplot(x1,[0,2],'k');
hold on;
fplot(x2,[0,2],'--k');
hold off;
legend('x','y');
title('plot');
xlabel('t');
ylabel('d');
I am increasing the linewidth, but messing up somewhere. In plot command, you can straightaway write 'LineWidth' in plot() itself, but no so in fplot. Any comments where I messed up?

Best Answer

Starting in R2016a, you can specify the 'LineWidth' property the same way you do for plot. For example:
>> fplot(x1,[0,2],'k','LineWidth',2);
In R2015b and earlier releases, you have to search for the object and set the line width. To set the widths of all the lines to 2:
>> set(findall(gca, 'Type', 'Line'),'LineWidth',2);
Or, to set the width of one line:
>> set(findobj(gca, 'Type', 'Line', 'Linestyle', '--'), 'LineWidth', 2);