An error occurred while trying to modify linewidth

3 views (last 30 days)
Hi all,
I have tried to modify the linewidth as follows:
plot(t,means(k,:)*10^13,color{c},linewidth(c)),
where color ={'b',':b','k',':k','r',':r'}; linewidth = [0.5,3,0.5,3,0.5,3];
This works correctly without linewidth but when linewidth is added I get an error: ??? Error using ==> plot Attempt to modify a property that is read-only. Object Name : line Property Name : 'BeingDeleted'.
Could someone please let me know what I am doing wrong, and how the linewidth can be modified?
Thanks, Maria

Accepted Answer

Stephen23
Stephen23 on 29 Sep 2014
Edited: Stephen23 on 29 Sep 2014
The documentation for the plot command states that you can set the LineSpec immediately after X and Y value arrays, which is why this works in your loop:
plot(t,means(k,:)*10^13,color{c})
because color{c} defines a LineSpec value (in your case, a color). According to the documentation the LineSpec can be any of "line style, marker symbol, and colorstring". Notice that this list does not include line width.
If you read the only section of the documentation that mentions line widths, you will see that this occurs under the section titled "Name-Value Pair Arguments". Name-Value Pairs are often used in MATLAB to enter optional arguments for many functions. You can read more information in the plot documentation.
For the sake of completeness, this is an example that the plot documentation contains, which includes changing the line width:
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
figure
plot(x,y,'--gs',...
'LineWidth',2,...
'MarkerSize',10,...
'MarkerEdgeColor','b',...
'MarkerFaceColor',[0.5,0.5,0.5])

More Answers (1)

Maria
Maria on 29 Sep 2014
Many thanks for the answer!
-Maria

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!