A small question about load matrix

1 次查看(过去 30 天)
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.

采纳的回答

Sean de Wolski
Sean de Wolski 2012-5-7
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by