plot using gline and change the color from black to red
12 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm editing an graph and I would like to add a vertical and a horizontal dashed line from the starred point to the coordinates. I tried using gline but i cannot change the line's color which confuses me. This is my code about the gline part:
hold on
vline = gline;
vline.Color='red'
vline.LineStyle='--'

but as you can see, the line is still black. Please help!With many thanks!
5 Commenti
dpb
il 5 Set 2018
Well, it can't be that precise code; Matlab is case-dependent an all the function names are lower case...and, what's the point of hold on twice; once the property is set 'on', it won't get any "onner". Not that that is the problem, just that application of the parsimony principle is a virtue in coding.
There doesn't seem to be any syntax issue that can be seen with what you've posted; unfortunately, you've always posted typed-in text at the input window, NOT cut-n-paste from the Matlab command window itself so we can't really tell for sure that what you actually executed is the same as what you've posted. It probably is, but there's that chance you did have a syntax error or some other mistype that caused the observed behavior.
Although, just for checking, what does
which -all gline
return at command line and does the symptom still occur if you try
clear gline
and then retry the comand?
Also, it would be good to check that
whos vline
returns a line handle; maybe you accidentally created a struct variable of the name and you're just storing into it instead of actually writing to the gline object.
Something of that sort is the most likely thing that is happening but we can't see your terminal from here to be able to discern such a thing...
Risposte (1)
KSSV
il 5 Set 2018
set(vline,'Color','r')
3 Commenti
KSSV
il 5 Set 2018
YOu run the line set once gain...It is working here for me.
x = 1:10;
y = x + randn(1,10);
scatter(x,y,25,'b','*')
lsline
mu = mean(y);
hold on
plot([1 10],[mu mu],'ro')
hline = gline; % Connect circles
set(hline,'Color','r')
dpb
il 5 Set 2018
Modificato: dpb
il 5 Set 2018
But the handle dot notation was introduced in R2014b and OP has R2018a so the syntax
vline.Color='r';
is also valid and the 'Color' property for line color abbreviation isn't required; 'red' is the full name and is also documented as valid value.
As several others have indicated, that syntax works correctly on several other respondents' systems as well so whatever it is is specific to the OP's system or some fluke in R2018a (I don't recall any of those who answered mentioned were using the same release or not).
Or, as noted above, perhaps there's a struct variable been created that he's storing into instead of writing to the line object if there's a typo or somesuch we can't see from what has been posted (which isn't the identical exact input from the terminal but a transcription of what was intended).
Vedere anche
Categorie
Scopri di più su Model Building and Assessment in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!