필터 지우기
필터 지우기

A small question about load matrix

조회 수: 1 (최근 30일)
Tommy
Tommy 2012년 5월 7일
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