How to add to values of a field?

3 ビュー (過去 30 日間)
Thibedi Malotana
Thibedi Malotana 2020 年 5 月 29 日
コメント済み: Cris LaPierre 2020 年 5 月 29 日
How can I add values to a field without overwriting the previous entry? In a for loop

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 5 月 29 日
編集済み: Cris LaPierre 2020 年 5 月 29 日
Use your loop counter variable to specify where to add the value.
By field do you mean in a structure?
for a = 1:3
b.field1(a) = val;
end
  3 件のコメント
Thibedi Malotana
Thibedi Malotana 2020 年 5 月 29 日
Struct1 = struct('Cm',[])
for n = 1:1:2
t = dir('*Filename*.xlsx')
t = t(n).name;
a = size(t);
b = a(1,2) - 5;
t = char(extractBetween(t,20,b));
t = struct(t,[])
Struct1.Cm = t
end
When the code is finished the only value in Cm is the last t for n = 2
Cris LaPierre
Cris LaPierre 2020 年 5 月 29 日
Structures can have many levels. Look at this doc page for more.

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by