Using the enter key to input multiple values for one variable

조회 수: 6 (최근 30일)
I am having some difficulty in obtaining a solution to change this previous code that I had splitting the multiple values with commas:
Acceldata=input('What are your accel values?( Separated by commas and from 0 deg to 270 deg)','s')
outA=regexp(Acceldata,',','split');
outAccel=outA(1:end);
I would like to modify this code, so after the user inputs their first value then hit the enter key, and then the input(Acceldata) appears again then they can enter their second value, hit the enter key and so on. I would then like the output of the input to be the values on different lines after being entered and stored.
Any suggestions or resolutions to apply?
  댓글 수: 2
Stephen23
Stephen23 2020년 7월 15일
You will need to use a loop. What do you want the user to enter to exit this cycle?
Alexandra Philip
Alexandra Philip 2020년 7월 15일
After the user enters 4 values will they be able to exit the cycle.

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

채택된 답변

Fangjun Jiang
Fangjun Jiang 2020년 7월 15일
outAccel=zeros(4,1)
for k=1:4
outAccel(k)=input('What are your accel value/');
end
  댓글 수: 3
Fangjun Jiang
Fangjun Jiang 2020년 7월 15일
outAccel as defined in above code is arry, not cell array. Use outAccel(1), not outAccel{1}. It is one-dimentional array so no need to use outAccel(1,1)
Alexandra Philip
Alexandra Philip 2020년 7월 15일
Ok, thank you. The code works smoothly now.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by