[SOLVED! - Two Errors: CAT arguments dimensions are not consistent - Assignment has fewer non-singleton rhs dimensions than non-singleton subscripts ]

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

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.
The main script that launch the function clear the workspace everytime is launched. vartheta is a local variable that lives only inside this function. size(...) report:
size(vartheta)
ans =
1 1
size(tstar)
ans =
1 1
If vartheta is an 1x1 (scalar), why matlab print on the screen
vartheta(:,:,1) =
0.0100
vartheta(:,:,2) =
0.0100
?????
Note that in many cases the script works fine but sometimes gives this error. I'm going crazy!! :(
Thanks for reply

Sign in to comment.

 Accepted Answer

If Pstima is a 3D array where each plane is 3x3, and tstar is a scalar, then if you define vartheta according to
vartheta=Pstima(3,3,tstar);
vartheta will be one 3x3 plane out of Pstima. size() should report that, not 1x1. Are you sure you didn't redefine size()? What does this say
which -all size
whos vartheta

2 Comments

If I define
vartheta=Pstima(3,3,tstar)
and tstar is a scalar, also vartheta should be scalar, right? Because I've assigned the element 3,3 of Pstima(:,:,tstar) to vartheta. This is the report:
whos vartheta
Name Size Bytes Class Attributes
vartheta 1x1 8 double
But Matlab continues to print this on screen:
vartheta(:,:,1) =
0.0100
vartheta(:,:,2) =
0.0100
which -all size
built-in (C:\Program Files\MATLAB\R2011a\toolbox\matlab\elmat\size)
size is a Java method % java.util.ArrayList method
size is a Java method % java.util.AbstractList method
size is a Java method % java.util.AbstractCollection method
size is a Java method % java.util.Collection method
size is a Java method % java.util.List method
size is a Java method % com.mathworks.mlwidgets.workspace.WhosInformation method
C:\Program Files\MATLAB\R2011a\toolbox\matlab\polyfun\@TriRep\size.m % TriRep method
C:\Program Files\MATLAB\R2011a\toolbox\matlab\iofun\@timer\size.m % timer method
C:\Program Files\MATLAB\R2011a\toolbox\matlab\iofun\@serial\size.m % serial method
C:\Program Files\MATLAB\R2011a\toolbox\matlab\timeseries\@tscollection\size.m % tscollection method
C:\Program Files\MATLAB\R2011a\toolbox\comm\comm\@gf\size.m % gf method
C:\Program Files\MATLAB\R2011a\toolbox\shared\controllib\engine\@InputOutputModel\size.m % InputOutputModel method
C:\Program Files\MATLAB\R2011a\toolbox\daq\daq\@daqdevice\size.m % daqdevice method
C:\Program Files\MATLAB\R2011a\toolbox\daq\daq\@daqchild\size.m % daqchild method
C:\Program Files\MATLAB\R2011a\toolbox\distcomp\parallel\@distributed\size.m % distributed method
C:\Program Files\MATLAB\R2011a\toolbox\distcomp\parallel\@codistributed\size.m % codistributed method
C:\Program Files\MATLAB\R2011a\toolbox\distcomp\lang\@Composite\size.m % Composite method
C:\Program Files\MATLAB\R2011a\toolbox\finance\ftseries\@fints\size.m % fints method
C:\Program Files\MATLAB\R2011a\toolbox\ident\ident\@idmodel\size.m % idmodel method
C:\Program Files\MATLAB\R2011a\toolbox\ident\ident\@idfrd\size.m % idfrd method
C:\Program Files\MATLAB\R2011a\toolbox\ident\ident\@iddata\size.m % iddata method
C:\Program Files\MATLAB\R2011a\toolbox\ident\nlident\@idnlmodel\size.m % idnlmodel method
C:\Program Files\MATLAB\R2011a\toolbox\ident\nlident\@idnlgrey\size.m % idnlgrey method
C:\Program Files\MATLAB\R2011a\toolbox\ident\nlident\@idnlfun\size.m % idnlfun method
C:\Program Files\MATLAB\R2011a\toolbox\imaq\imaq\@videosource\size.m % videosource method
C:\Program Files\MATLAB\R2011a\toolbox\imaq\imaq\@videoinput\size.m % videoinput method
C:\Program Files\MATLAB\R2011a\toolbox\instrument\instrument\@visa\size.m % visa method
C:\Program Files\MATLAB\R2011a\toolbox\instrument\instrument\@udp\size.m % udp method
C:\Program Files\MATLAB\R2011a\toolbox\instrument\instrument\@tcpip\size.m % tcpip method
C:\Program Files\MATLAB\R2011a\toolbox\instrument\instrument\@icgroup\size.m % icgroup method
C:\Program Files\MATLAB\R2011a\toolbox\instrument\instrument\@icdevice\size.m % icdevice method
C:\Program Files\MATLAB\R2011a\toolbox\instrument\instrument\@gpib\size.m % gpib method
C:\Program Files\MATLAB\R2011a\toolbox\mpc\mpc\@mpc\size.m % mpc method
C:\Program Files\MATLAB\R2011a\toolbox\robust\robust\@uss\size.m % uss method
C:\Program Files\MATLAB\R2011a\toolbox\robust\robust\@umat\size.m % umat method
C:\Program Files\MATLAB\R2011a\toolbox\robust\robust\@ufrd\size.m % ufrd method
C:\Program Files\MATLAB\R2011a\toolbox\robust\robust\@ndlft\size.m % ndlft method
C:\Program Files\MATLAB\R2011a\toolbox\robust\robust\@icsignal\size.m % icsignal method
C:\Program Files\MATLAB\R2011a\toolbox\robust\robust\@atom\size.m % atom method
C:\Program Files\MATLAB\R2011a\toolbox\shared\statslib\@dataset\size.m % dataset method
C:\Program Files\MATLAB\R2011a\toolbox\shared\statslib\@categorical\size.m % categorical method
C:\Program Files\MATLAB\R2011a\toolbox\symbolic\symbolic\@sym\size.m % sym method
Thanks for reply
I'm Sorry but I've erroneously click on "accepted answer" but problem is NOT SOLVED !!

Sign in to comment.

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

I have found the problem. Sometimes tstar is a scalar sometimes vector. When is vector, matlab gave the error (rightly!)
Thanks to all! :)

Sign in to comment.

Categories

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

Products

Tags

Community Treasure Hunt

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

Start Hunting!