How to store string values from a for loop into a cell array?
    11 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hi. I want the user to input an arbitrary number, and then set up a for loop that asks the question
"Enter a string" as many times as the user indicated above with the first input.
I then want to store all these string values into a cell array, and be able to retrieve these strings later.
How do I do this?
prompt = "Enter a number";
x = input(prompt)
for i=1:x
  %Code that asks user to input string
end
0 件のコメント
採用された回答
  Moe_2015
      
 2016 年 8 月 15 日
        prompt = 'Enter a number: ';
x = input(prompt);
for i=1:x
  user_string = input('Enter a string: ');
  all_strings{i} = user_string;
end
3 件のコメント
  Moe_2015
      
 2016 年 8 月 15 日
				
      編集済み: Moe_2015
      
 2016 年 8 月 15 日
  
			Yes, replace
user_string = input('Enter a string: ');
with
user_string = input('Enter a string: ','s');
This way you will not need any single quotations and you just have to enter whatever text you want as an input and it will treat it as a string.
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Characters and Strings についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

