필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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
Walter Roberson
Walter Roberson 2018년 11월 2일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2018년 11월 2일
편집: Star Strider 2018년 11월 2일
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

추가 답변 (3개)

Caglar
Caglar 2018년 11월 2일
편집: Caglar 2018년 11월 2일
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 2018년 11월 2일
편집: Matt J 2018년 11월 2일
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 2018년 11월 2일
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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by