You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Subscripted assignment dimension mismatch (size [1 x 1] ~= size [30 x 30]).
1 view (last 30 days)
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
ok the line which gives me error is T(i+1,j+1) = (T(i+1,j)+C*(T(i,j+1))-D*(T(i,j+1))+(D*2*Tg))/B;
the input coming from other blocks are T_f, Tg and m1 which are values for temperatures and mass flow rate. the temperatures coming from recorded data are in the format 35040x2 double while m1, which is calculated in a different block is 1x1 double timeseries.
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
yes B and C have m1 inside which comes from a different block. what I did,I fixed m1=0.5, and what I got out this time is not the same error, but T_sb1 as 2x30 double, which has values different from I was expecting. running it just in matlab with fix values t_f=70, tg=15 and m1=0.5 it works correctly.
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
Edited: MICHELE
on 8 May 2014
I did it in that way, because I was using i-1 and j-1, but this gave me error. The idea of the equation is that the temperature propagation depends from the temp of the previous time step (j) at the given x (i+1) and from the temp of the previous x value (i+1,j).
regarding m1, it comes from a different block and it is 1x1timeseries, being a block output. According to this how could I solve this issue? I do not have clear how to deal with the dimensions of my input and my output and how to integrate smoothly the different blocks, because m1 is an important parameter which is calculate at each time step j and depends from the temp profile.
MICHELE
on 8 May 2014
What about if I change all my data input in timeseries data? Could it help solving the issues?
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
Thanks for the suggestions.
just to clarify, the code I enclosed determines a value of T for each time step j. This T goes to a different block, where at each time step, according to T and to another given input, it calculates m1 (which is kg/s). Once it calculates m1, it goes back to the code I enclosed and at each time step it calculates T. As default (I assumed) Simulink defines m1 as a timeseries; what I want is that my code should use each of the 30 values (in this simple case) and do the calculation.
Also, just to have a go, I changed Tg from a constant value to a vector nx2. When I run the simulation it says that there is a mismatching between T(1,1)=Tg (Subscripted assignment dimension mismatch (size [1 x 1] ~= size [35040 x 2]). The problem I recognize (if I am not wrong) is to make the code reading each and use every single data of the different input/vector.
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
Edited: MICHELE
on 8 May 2014
ok the 35040 are the recorded temp for each 15min of 1 year. T(1,1) represents the starting point, where the temp are equal to the ambient temp. I could overcome this one, simply assigning a constant average value. but for the rest of them, say T(1,j+1)=T_f or T(i+1,j+1) = (T(i+1,j)+C*(T(i,j+1))-D*(T(i,j+1))+(D*2*Tg))/B I want that at each j the code should consider each single T_f value (of the 35040 ones) as well as for m1 (included in B and C calculation). Clearly, I could consider instead of 1year, 1week or 1day but I think the prob would be the same.
MICHELE
on 8 May 2014
I forgot to mention that ambient temp is Tg and that the purpose of the model will be to simulate the temp profile of my system considering the ambient temp and T_f (which represent the temp coming in from the heat generation point).
Answers (0)
See Also
Categories
Find more on Sources in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)