フィルターのクリア

How can I create an array from the past values in a loop?

2 ビュー (過去 30 日間)
Tatiana Kobachishvili
Tatiana Kobachishvili 2021 年 10 月 25 日
編集済み: Ive J 2021 年 10 月 25 日
I have a loop code that gives the str a different value each time it runs but how would I combine all those string values into one?
For example my str values are 'Coco' , 'Gustavo', 'Ellen'
These are passed values of the str. So right now str would be equal to 'Ellen'.
how can I make an array that contains all of them?

回答 (1 件)

Ive J
Ive J 2021 年 10 月 25 日
something like this?
n = 10;
str = strings(n, 1);
for i = 1:n
% do whatever
str(i, 1) = gimmeMystr;
end
  2 件のコメント
Tatiana Kobachishvili
Tatiana Kobachishvili 2021 年 10 月 25 日
Hmm, I'm not sure if this would work. Maybe I was not clear with my question. Let me write out my code:
names = ['Coco Gustavo Ellen'] %there are x amount of names
charVec = []
while ~isempty(names)
[name,names] = strtok(names, ' ');
charVec = char(name) %this is where I need help as this only displays the current value
%of name not all of them.
end
As you can see, I want the names in one string and I am using strtok to seperate them, and then I want to put it back together as ['Coco' 'Gustavo' 'Ellen']
Ive J
Ive J 2021 年 10 月 25 日
編集済み: Ive J 2021 年 10 月 25 日
What's your goal here? If you wanna split the input string, why don't you try split?
names = ["Coco Gustavo Ellen", "hej bye now or never"];
sepnames = arrayfun(@split, names, 'uni', false);
sepnames{1}
ans = 3×1 string array
"Coco" "Gustavo" "Ellen"
sepnames{2}
ans = 5×1 string array
"hej" "bye" "now" "or" "never"

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by