Iterating in a dataset encompassing a structure
Show older comments
Hello all,
I have an issue accessing an array in a dataset table which emcompasses a struct in it.
I want to build an array which contains eigenvectors from different rank during the Johansen test.
I have the following :
basevar = evalin('base', x)
[c,n] = size(basevar)
arrcoef = zeros(n)
[h,pvalue,stat,cValue,mles] = jcitest(basevar,'model','H1', 'lags', 1)
Here i get, a dataset called mles.
Inside this dataset I have :
mles =
r0 r1
t1 [1x1 struct] [1x1 struct]
and when i do mles.r0 I have
paramNames: {5x1 cell}
paramVals: [1x1 struct]
res: [1498x2 double]
EstCov: [2x2 double]
eigVal: 0.0106
eigVec: [2x1 double]
rLL: -1.2002e+03
uLL: -1.1902e+03
Here I want to get the eigVec array.
So i open a loop :
for i = 1:n
coeff = double(pvalue(:,i))
if 0.05 - coeff && 0.05 - coeff > 0
arcoeff(i) = mles.r(i).eigVec
end
end
I can see the issue it comes from this part : mles.r(i), it takes r as a variable which is normal, I want to know how to make this .r0 reactive to an iteration. I tried with {} and putting the name in something like this
a = mles.Properties.VarNames{i}
mles.a.eigVec
But this does not work.
Do you know how can make this reactive to my iterative value i?
thanks
D
Accepted Answer
More Answers (1)
arcoeff{i} = mles.(sprintf('r%d', i)).eigVec;
Categories
Find more on Common Operations 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!