Loading data into function workspace
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Anurag Kamal
le 27 Mar 2019
Réponse apportée : Anurag Kamal
le 28 Mar 2019
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!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/210770/image.png)
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.
0 commentaires
Réponse acceptée
Kojiro Saito
le 27 Mar 2019
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.
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!