How to create string array using inpu

8 ビュー (過去 30 日間)
Caroline
Caroline 2014 年 10 月 10 日
編集済み: Bruno Pop-Stefanov 2014 年 10 月 10 日
I understand how to store strings in arrays as in matlab will only store vectors with the same dimensions. However I need to create the vector from input from the user. So I'm not sure how I'm supposed to store it. I need to be able to store multiple strings in one and be able to reference them. For example I need to be able to do: word(1)=input('enter word','s') and the user gives the word and moves on to word(2)

採用された回答

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014 年 10 月 10 日
編集済み: Bruno Pop-Stefanov 2014 年 10 月 10 日
You need to use cell arrays:
for i=1:5
word{i} = input('Enter word:\n','s');
end
Cell arrays can store mixed data types and of varying sizes. For example, a cell array can contain an n-by-m matrix as its first element and a scalar as its second element, or it can contain strings of varying length.
Cell arrays work very similarly to regular arrays. The small difference in the syntax is the use of curly braces { and } (see code above).

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by