Problem using LineStyle

When I use LineStyle to only change the shape of the line, it works fine. When I use it to change the color, it gives me this error:
??? Error using ==> line Bad property value found. Object Name : line Property Name : 'LineStyle'.
For example,
line(....'LineStyle', ':') works fine, but line(....'LineStyle', 'k:') will cause a crash
Can someone explain why?

 Akzeptierte Antwort

Luke Chen
Luke Chen am 5 Apr. 2011

0 Stimmen

I am writing this function:
function finalPositions = networkEdit(weights, names, nodeStyle, linkStyle)
linkStyle is one string that determines the shape and color of all lines in the subsequent plot. So if linkStyle = 'k:', it should make all lines black and dotted. If I want black dotted lines, do I have to take linkStyle and break it up into 'k' and ':' or is there a way to use the string 'k:' without breaking it up?

6 Kommentare

Matt Fig
Matt Fig am 5 Apr. 2011
This kind of double argument is meant for the PLOT function, which creates lines. If you want to do it that way, use PLOT. Otherwise you will have to break it up or make two input arguments.
Luke Chen
Luke Chen am 5 Apr. 2011
For my program, I have a bunch of points that are plotted using the plot() function. Only some of these points are connected by lines, and the lines are specified only after the points have been plotted. Thus, I had to use the line() function to draw the lines in between points.
In this case, if I put LineStyle with the plot() function, will it affect the lines I draw later using the line() function?
Matt Fig
Matt Fig am 5 Apr. 2011
PLOT and LINE can be made to do the same thing. One is more convenient for one kind of data, that is all. For example, these are identical:
subplot(1,2,1)
plot([0 0],[0 1])
subplot(1,2,2)
line([0 1;0 1],[0 0;1 1])
xlim([-1 1])
So you can translate any graph made by a call to PLOT into a similar graph made by a call to LINE.
Luke Chen
Luke Chen am 5 Apr. 2011
I just tried using plot to draw the lines and I used the double arguments like 'k:' and it still gives the same error
Matt Fig
Matt Fig am 5 Apr. 2011
Then you did something else wrong.
plot(1:2,3:4,'k:') % Works for me....
Luke Chen
Luke Chen am 5 Apr. 2011
Deleted 'LineStyle' from the arguments and it works now.
Thank you so much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt Fig
Matt Fig am 5 Apr. 2011

0 Stimmen

That is because you are using the LineStyle property to try to change the Color property.
L = plot(1:10);
set(L,'linestyle',':','color','k')

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by