Clear Filters
Clear Filters

Conversion to logical from struct is not possible.

7 views (last 30 days)
Hi! I am currently working on a Markov Switching DCC-GARCH model using Matlab and got stuck. I believe someone has asked this question before but as I am very new to Matlab, I still can't figure out how to fix mine. Here's the code I use:
addpath('MS_Regress-Matlab-master');
addpath('m_Files');
addpath('data_Files');
[filename,pathname]=uigetfile('*.xlsx');
[data,textdata,raw] = xlsread(filename,1);
date=datenum(textdata(2:397,1),'dd/mm/yyyy');
s_start = '01/01/1989';
s_end = '01/12/2021';
date_find=datenum([s_start; s_end],'dd/mm/yyyy');
ss=datefind(date_find(1,1),date);
se=datefind(date_find(2,1),date);
cant=data(1:396,1:2);
R_eq=diff(log(cant));
dep=R_eq; % Defifines the dependent variables in system
nLag=3; % Number of vector autoregressive lags in 2x1 system (p)
k=2; % Number of states/regimes (K)
doIntercept=1; % Add intercept to equations (1= Yes; 0= No) (whether ? is MS)
advOpt.distrib='Normal';
advOpt.std_method = 1; % Defifining the method for calculation of standard errors.
advOpt.diagCovMat = 0; % Whether we will estimate by MLE also MS covariances (H feature)
advOpt.doPlots = 1; % Does not produce automatic plots (you are in charge of that!)
advOpt.printIter = 0; % When set to 0, does not print iterations to the screeen
[Spec_Out]=MS_VAR_Fit_tvtp(dep,nLag,k,doIntercept,advOpt);
Screenshot:
Does anyone know how to fix this?
Thank you!

Accepted Answer

Tushar
Tushar on 17 Jun 2023
Hello Alya,
Here is the Link to the question with the similar issue.
But with your code it appears like the MS_VAR_Fit_tvtp() function is returning a structure. So you must be familiar with the properties of the structure being returned. Therefore, a possible solution could be to modify the function MS_VAR_Fit_tvtp to return the specific fields of the structure that you are interested in, or you can assign the structure to multiple output variables that correspond to its fields. For example:
[Parameters, LogLikelihood, Residuals] = MS_VAR_Fit_tvtp(dep, nLag, k, doIntercept, advOpt);
Replace Parameters, LogLikelihood, and Residuals with the actual field names of the Spec_Out structure that you want to extract and use in your further analysis.
  5 Comments
Walter Roberson
Walter Roberson on 17 Jun 2023
You are mssing the px parameter in your call to MS_VAR_Fit_tvtp
Alya
Alya on 19 Jun 2023
Oh! I thought it was unnecessary as the older function didn't require it. Thank you for the help.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!