Effacer les filtres
Effacer les filtres

A small question about load matrix

1 vue (au cours des 30 derniers jours)
Tommy
Tommy le 7 Mai 2012
I want to load a matrix in a function, so I save the matrix of "randn(M,N)" as "randn_DBba_modified.mat". In the function below:
...
Mat=load('randn_DBba_modified.mat');
...
for j=1:N
...
asset(:,j+1)=asset(:,j)+((asset(:,j).*(r+omega*(mu-r)))+40*contri(:,j)-15*b(:,j))*dt+omega*sigma*asset(:,j)*sqrt(dt).*Mat(:,j);%asset function
...
and get the error notification of "??? Undefined function or method 'times' for input arguments of type 'struct'.
Error in ==> function_1_3_2 at 39 asset(:,j+1)=asset(:,j)+((asset(:,j).*(r+omega*(mu-r)))+40*contri(:,j)-15*b(:,j))*dt+omega*sigma*asset(:,j)*sqrt(dt).*Mat(:,j);%asset function"
I bypass the useless code above.
I want to know where I did is wrong since if I set a matrix in the code instead of loading one, the function works well.
Thank you.

Réponse acceptée

Sean de Wolski
Sean de Wolski le 7 Mai 2012
dbstop if error
Then run the code. The debugger will stop on the line causing the error. It should be obvious at this point.
OKAY, hint! The mat file loaded as a struct since you assigned it to a variable. If you want to load the variables individually:
load mymatile.mat
If you want to load them to a struct, do as you did but then reference them by:
Mat.varName
  1 commentaire
Tommy
Tommy le 7 Mai 2012
THX a lot!

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by