How do i set the marker and line commands to accept the symbols as inputs

1 Ansicht (letzte 30 Tage)
p.LineStyle = input('Select which line style you would like: ','s');
while p.LineStyle ~= ('''-''' | '''--''' | ''':''' | '''-.''' | '''none''')
p.LineStyle = input('Refer to the PDF document for valid inputs: ');
end
I get the error 'Matrix dimensions must agree'
  1 Kommentar
Walter Roberson
Walter Roberson am 2 Nov. 2018
Note that if p is a Mathworks graphics object, then setting p.LineStyle to something invalid would error before getting to the while. That is why I store into a different variable and leave the setting of p.LineStyle until after the input has been validated.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 2 Nov. 2018
Bearbeitet: Star Strider am 2 Nov. 2018
See if the strcmpi (link) function will do what you want.
This works for me:
p.LineStyle = input('Select which line style you would like: ','s');
while ~strcmpi(p.LineStyle, {'''-''' , '''--''' , ''':''' , '''-.''' , '''none'''})
p.LineStyle = input('Refer to the PDF document for valid inputs: ');
end

Weitere Antworten (3)

Caglar
Caglar am 2 Nov. 2018
Bearbeitet: Caglar am 2 Nov. 2018
You need to make it
input('Refer to the PDF document for valid inputs: ','s')
Check input help page for the reason of parameter 's'.

Matt J
Matt J am 2 Nov. 2018
Bearbeitet: Matt J am 2 Nov. 2018
while ~ismember( p.LineStyle ,{'-',':','-.','--','none'})
disp 'Refer to the PDF document for valid inputs:', disp ' ';
p.LineStyle = input('Select which line style you would like: ','s');
end

Walter Roberson
Walter Roberson am 2 Nov. 2018
valid_styles = {'-', '--', ':', '-.', 'none'};
while true
LineStyle = input('Select which line style you would like: ','s');
if ismember(LineStyle, valid_styles)
p.LineStyle = LineStyle;
break;
end
fprintf('valid styles are: %s\n', strjoin(valid_styles, ' '));
end

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by