Matlab Difference between - and - when changing LineStyle

I have a program in which I want to change linestyle using input, but I have problems changing from - to and from. it gives the message "The selected style is already in use", how can I make the program see the difference between them without having to write spaced as - -?

style=input('Give new style ( :, --, -., -): ','s'); h(id) = plot_handles(id); if get(h(id), 'LineStyle')==(style) disp('The choosen style is already used!'); else set(h(id), 'LineStyle', style); end 
+4
source share
1 answer

When you use == , you will get a piecemeal comparison as shown below:

 '-' == '--' ans = 1 1 

Try using isequal :

 isequal('-' ,'--') ans = 0 

I think this should work:

 if isequal(get(h(id), 'LineStyle'), (style)) disp('The choosen style is already used!'); else set(h(id), 'LineStyle', style); 
+3
source

Source: https://habr.com/ru/post/1485305/


All Articles