필터 지우기
필터 지우기

Write a script that will keep prompting the user for a string then stores them in a cell array and prints to display all strings in this cell array:

조회 수: 1 (최근 30일)
string=input('PLEASE INPUT A STRING:','s');
string1={i}
I believe I would need a for loop and to use celldisp but I am having trouble figuring out how to do those.

채택된 답변

Image Analyst
Image Analyst 2013년 10월 20일
편집: Image Analyst 2013년 10월 20일
Try this:
maxCount = 10; % a "Failsafe"
counter = 1; % Failsafe.
while counter <= maxCount
string = input('PLEASE INPUT A STRING (Type quit to exit):', 's');
if ~isempty(strfind(lower(string), 'quit'))
break;
end
strings{counter} = string
counter = counter + 1;
end
fprintf('Done!\n');
celldisp(strings);
  댓글 수: 2
Nora
Nora 2013년 10월 20일
That works! How would I be able keep asking for user input till the user hits the return key without inputting a string instead of using quit?
Image Analyst
Image Analyst 2013년 10월 20일
편집: Image Analyst 2013년 10월 20일
Please mask the answer as accepted and let people know in your other duplicate question that you have a solution. In your duplicate question you said you want to call celldisp() so I added that at the end of the code, though it was already displaying it inside the loop because I left off the semicolon on the assignment line.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by