Loading data into function workspace

21 ビュー (過去 30 日間)
Anurag Kamal
Anurag Kamal 2019 年 3 月 27 日
回答済み: Anurag Kamal 2019 年 3 月 28 日
I want to load a workspace variable into a function that is called deep inside the whole program, but somehow even after load a saved mat file, it can't read the struct!
drivecycle =
struct with fields:
cell: [1×1 struct]
Reference to non-existent field 'time'.
Error in getInputCurrentDensity (line 6)
I_density=interp1(drivecycle.time,drivecycle.I,t)
However, the variable does have the existing field, time.

採用された回答

Kojiro Saito
Kojiro Saito 2019 年 3 月 27 日
If a variable is assinged to output of load, the variable is struct (Ref: document). So, you need to extract an array from struct using drivecycle = drivecycle.drivecycle.
I think the following will work.
drivecycle = load('dctest.mat');
drivecycle = drivecycle.drivecycle;
I_density = interp1(drivecycle.time,drivecycle.I,t);
Or, just
load('dctest.mat')
I_density = interp1(drivecycle.time,drivecycle.I,t);
would also work.

その他の回答 (1 件)

Anurag Kamal
Anurag Kamal 2019 年 3 月 28 日
That was fast! I was just missing the internal heirarcy of variables, and using this worked:
I_density=interp1(drivecycle.cell.time,drivecycle.cell.I,t)
Thanks!

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by