Using the enter key to input multiple values for one variable

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 日

0 投票

outAccel=zeros(4,1)
for k=1:4
outAccel(k)=input('What are your accel value/');
end

3 件のコメント

Alexandra Philip
Alexandra Philip 2020 年 7 月 15 日
Thank you, I was able to get the accel value to enter on separate lines.
I am having trouble storing my values into a table as if I tried to create a variable that will be put into the table such as:
Accel0=[outAccel{1,1}]';
Each variable value will be in each column of the table
I get this error:
Brace indexing is not supported for variables of this type.
Error in Tumbleuser_final (line 18)
Accel0=[outAccel{1,1}]';
Any suggestions?
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 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by