[SOLVED! - Two Errors: CAT arguments dimensions are not consistent - Assignment has fewer non-singleton rhs dimensions than non-singleton subscripts ]
Show older comments
Hi, I have this error problem while Matlab try running this function from a script (I've post only a part of it because the problem is here):
if binary(numseg).adfp==incrocio(1:length(binary(numseg).adfp));
x=[binary(numseg).firstpoint' ; midpoint];
varx=(binary(numseg).raggiofp/3)^2;
vary=varx;
elseif binary(numseg).adsp==incrocio(1:length(binary(numseg).adsp));
x=[binary(numseg).secondpoint' ; midpoint];
varx=(binary(numseg).raggiosp/3)^2;
vary=varx;
end
vartheta=Pstima(3,3,tstar);
P=[varx 0 0 ; 0 vary 0 ; 0 0 vartheta];
xstimawall=x;
Pstimawall=P;
Pstima(:,:,tstar)=P;
Pplot(:,:,tstar)=P;
Xstima(:,tstar) = x;
Xplot(:,tstar)=x;
Note that Pstima is a 3D Array of 3x3 matrix and tstar is a scalar index between 1 and length(Pstima)
- First error: If I try running the function I have this error:
??? Error using ==> horzcat CAT arguments dimensions are not consistent.
Error in ==> startekfreprocessing at 87 P=[varx , 0 , 0 ; 0 , vary , 0 ; 0 , 0 , vartheta];
The problem is in vartheta. The variable appears to be a scalar but if I print vartheta and P on screen(I haven't put the ";" in vartheta and P):
vartheta =
0.0100
P =
3.0044 0 0
0 3.0044 0
0 0 0.0100
vartheta(:,:,1) =
0.0100
vartheta(:,:,2) =
0.0100
Why Mathlab print vartheta first like a scalar and then like a 3D Array of 2 1x1 matrix???
- Second error: If I try to solve the problem in this way:
P=[varx , 0 , 0 ; 0 , vary , 0 ; 0 , 0 , vartheta(1,1)]; (%% horzcat with vartheta(1,1) instead of vartheta)
Mathlab gave me this error:
??? Assignment has fewer non-singleton rhs dimensions than non-singleton subscripts
Error in ==> startekfreprocessing at 91 Pstima(:,:,tstar)=P;
...and print this on the screen:
vartheta =
0.0100
P =
3.0044 0 0
0 3.0044 0
0 0 0.0100
vartheta(:,:,1) =
0.0100
vartheta(:,:,2) =
0.0100
P =
3.0044 0 0
0 3.0044 0
0 0 0.0100
Please help me! Thank you so much...
3 Comments
dpb
on 10 Jul 2013
what do
size(tstar) size(vartheta)
return?
Also clear the workspace and try again; you may have the results of a previous typo hanging around.
The second case--if there's a size problem w/ [...] then horzcat() is going to have the same problem so there's no point in trying to finesse your way around a dimensions mismatch error.
Francesco
on 11 Jul 2013
Accepted Answer
More Answers (1)
Please type this in the command window:
Pstima = rand(3, 3, 5);
tstar = 2;
vartheta = Pstima(3, 3, tstar);
whos('vartheta')
vartheta(:,:,1)
vartheta(:,:,2)
If this shows the expected behavior, insert it into the code and check, what might be the difference.
I'm convinced, that there is a 100% not magic explanation for this behavior. Either you type "whos vartheta" and "vartheta(:,:,1)" in different workspaces, or the DISP or DISPLAY functions are shadowed, or a similar trick.
1 Comment
Francesco
on 11 Jul 2013
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!