A small question about load matrix
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Sean de Wolski
on 7 May 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
More Answers (0)
See Also
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!