Using a for loop for a structure

1 回表示 (過去 30 日間)
Amanda Chun
Amanda Chun 2018 年 2 月 4 日
編集済み: James Tursa 2018 年 2 月 4 日
I have a 1x1 structure with 10 field elements 'trial1','trial2',etc. each field corresponds to a ~3000x3 matrix (the matrices are not all the same length). I want to manipulate the 3rd column of each matrice and return it back into the matrix and structure. So far I have the code below, but I'm getting an error "Reference to non-existent field 'field'." Does anyone know what I'm doing wrong? I'm pretty new to structures and cell arrays.
for field = fieldnames(s)
s.field{1}(:,3) = s.field{1}(:,3).*(1/pconv).*(1/Vin)+patm;
end
  1 件のコメント
Amanda Chun
Amanda Chun 2018 年 2 月 4 日
編集済み: James Tursa 2018 年 2 月 4 日
I believe I fixed it, needed to insert parentheses around "field". This works
for field = fieldnames(s)
s.(field{1})(:,3) = s.(field{1})(:,3).*(1/pconv).*(1/Vin)+patm;
end

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

回答 (0 件)

カテゴリ

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