Subscripted assignment dimension mismatch (size [1 x 1] ~= size [30 x 30]).
Show older comments
Hi, I am new on MATLAB/SIMULINK environemt. I am trying to add a matlab function box inside a simulink model. I am importing some of the input signals from the workspace but i got the errors: Subscripted assignment dimension mismatch (size [1 x 1] ~= size [30 x 30]).
Also, how should the input dimensions be related to the script?
Below the script of the matlab fcn block
Thanks a lot
function T_sb1 =fcn(Tg,T_f,m1,U_p1)
cp=4.186;
L=30;
n=10;
dx=L/(n+1);
dt=900;
D=150;
dV=((D/(2*1000))^2)*pi*dx;
dA=((D/1000)*dx*pi);
A=((D/(2*1000))^2*L*pi);
% m1=0.5;
ro=1000;
B=(1+((m1/(dV*ro))*dt)+(U_p1*dA*dt/(2*dV*ro*cp)));
C=(m1*dt/(dV*ro));
D=(U_p1*dA*dt/(2*dV*ro*cp));
T=zeros(n,n);
for j=1:n,
for i=1:n,
T(1,1)=Tg;
T(i+1,1)=Tg;
T(1,j+1)=T_f;
T(i+1,j+1) = (T(i+1,j)+C*(T(i,j+1))-D*(T(i,j+1))+(D*2*Tg))/B;
end
end
T_sb1=T(n,:)';
12 Comments
Geoff Hayes
on 7 May 2014
Michele - Which line of code did was the error raised for, and what are your inputs into this function?
MICHELE
on 7 May 2014
Geoff Hayes
on 7 May 2014
Ok - so the all inputs are 1x1 double values (with exception of m1). The error seems to suggest that there is an assignment problem at this line. If T is simply 10x10 matrix, then at T(i+1,j+1) we are expecting to assign one double value only but are in fact assigning a 30x30 matrix (given the error).
So there must be something wrong with the dimensions of some of the factors in this equation - either B, C, D, or Tg. I can't reproduce exactly your problem, since I don't have the actual inputs (unless you want to post them) but if you were to put a breakpoint at this line, re-run the function and once the code pauses here, what are the dimension of B, C, D, and Tg? Do they make sense for what the code is expecting?
MICHELE
on 7 May 2014
Geoff Hayes
on 7 May 2014
When m1 is fixed, it is just a double. But when it is a 1x1 time series object, then things get more tricky and you can't treat it as if it were a double.
One thing I noticed in your code, is that you set n to 10 and so your T matrix becomes 10x10. The code then iterates for i and j from 1 to n. But part of the code that follows expands your matrix T by assigning something to T(i+1,1) and T(1,j+1) and T(i+1,j+1) which, when i and/pr j are 10, adds an additional row and column to T. Is this intentional?
MICHELE
on 8 May 2014
Geoff Hayes
on 8 May 2014
Michele - with respect to the iterating outside of the dimensions of T, you could perhaps just iterate from 1 to n-1 for both i and j. That way you never exceed your matrix dimensions.
As for using all time series objects, no, I don't think that would work. Maybe I missed it from above, but what does the time series object m1 represent (i.e. units?) and how does that relate to your equation? You probably want to be using the .Data portion of the m1 and maybe the .Time as well (does your equation care about that?).
MICHELE
on 8 May 2014
Geoff Hayes
on 8 May 2014
Right - you get the error since you are trying to assign a 35040x2 matrix to a single element within T. But that is a lot of temperatures to have to evaluate…are you sure that is what is required?
MICHELE
on 8 May 2014
Answers (0)
Categories
Find more on Event Functions 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!