Assignment has more non-singleton rhs dimensions than non-singleton subscripts in UKF

I'm trying to apply the unscented kalman filter as elaborated in the Artigo , to perform the estimation of the lambdah parameter of a time series. When implementing the code I get the following error
The commands in line 62 are hXi (:, k) = h (fXi (:, k)); and the error message i
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in Parametro_UKF (line 62) hXi(:,k) = h(fXi(:,k)); %h(Xi)
Hence I do not know how to do it because my measurement function only has three inputs of the five, that is, I only have the series of three variables. How to proceed, I'm trying to calculate the prediction of the measure through function h and Sigma Fxi points. I know there has to be dimensions, but I can not fathom how to correct.
It follows the implanted codes for the accomplishment of the parameter estimation.
I appreciate any help! If you notice any more errors please let me know, I do not know how to program very well!

6 Comments

Error using load
Unable to read file 'dados.mat'. No such file or directory.
Error in Parametro_UKF (line 4)
load('dados.mat')
I uploaded the file, if you can help I'm very grateful!
You have
h=@(x)[x(1) 0 0 0 0 0; % measurement equation
0 x(2) 0 0 0 0;
0 0 x(3) 0 0 0];
which creates a 3 x 6 matrix from the input vector.
You have
hXi = zeros(m, 2*n+1);
for k = 1:2*n+1
hXi(:,k) = h(fXi(:,k)); %h(Xi)
end
The right side produces a 3 x 6 matrix, but the left side describes a column vector. You cannot store a 3 x 6 matrix into a column vector.
We can tell from the way you initialized hXi that you are expecting h to output a 3 x 1 array, but you have clearly coded it to return a larger size.
How could I describe the method without this error occurring? I understand that the dimensions are giving problem. But I do not know how to fix it. Can you help me?
Out of those 18 values, which 3 would you like to store in hXi(:,k) ?
I did not quite understand what you meant, sorry. Actually I would like to perform the same process that was done previously
[Xi, W] = SigmaPoints(x, P, 0);
fXi = zeros(n, 2*n+1);
for k = 1:2*n+1
fXi(:, k) = f(Xi(:,k));
end
[xp, Pp] = UT(fXi, W, Q);
only with h of size 3 x 6. And then apply the UT function in that matrix.

Sign in to comment.

 Accepted Answer

hXi = zeros(18, 2*n+1);
for k = 1:2*n+1
hXi(:,k) = reshape( h(fXi(:,k)), [], 1); %h(Xi)
end

3 Comments

This answer is more than acceptable, but I come across another problem putting the dimensions in that way again give problem, in the case
Matrix dimensions must agree.
Error in UT (line 15)
xcov = xcov + noiseCov;
Error in Parametro_UKF (line 66)
[zp, Pz] = UT (hXi, W, R);
This is because my noise matrix R is 3x3 and theoretically my problem has no way to increase it. How can I continue to increase in any way? So do not lose property?
Well, you can do things like
hXi = cell(1, 2*n+1);
zp = cell(1, 2*n+1);
Pz = cell(1, 2*n+1);
for k = 1:2*n+1
hXi{k} = h(fXi(:,k)); %h(Xi)
[zp{k}, Pz{k}] = UT(hXi{k}, W, R);
end
Pxz = zeros(n, m);
for k = 1:2*n+1
Pxz = Pxz + W(k)*(fXi(:,k) - xp)*(hXi{k} - zp{k})';
end
but it will not work in the Pxz calculation.
(fXi(:,k) - xp) will be 6 x 1
hXi{k} will be 3 x 6. zp{k} will be 3 x 1. Since R2016b it has been legal to take 3 x 6 minus 3 x 1, which would be treated like bsxfun(@minus, 3x6, 3x1) which would give a 3 x 6 result. Then the conjugate transpose of that is taken, giving a 6 x 3 result.
And now you are stuck, since you cannot use * between a 6 x 1 and a 6 x 3.
You appear to be expecting a 6 x 3 result. The only way to get that out of a * with a 6 x 3 is if the first expression were to give a 6 x 6.
You need to trace out exactly what size you are expecting from each result.
Thank you very much, I will think about everything that was said here and rethink some things. Thanks for taking the time to help me, and it helped a lot!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

GTA
on 18 Sep 2018

Commented:

GTA
on 19 Sep 2018

Community Treasure Hunt

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

Start Hunting!