Subscripted assignment dimension mismatch (size [1 x 1] ~= size [30 x 30]).
1 次查看(过去 30 天)
显示 更早的评论
MICHELE
2014-5-7
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 个评论
Geoff Hayes
2014-5-7
Michele - Which line of code did was the error raised for, and what are your inputs into this function?
MICHELE
2014-5-7
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
2014-5-7
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
2014-5-7
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
2014-5-7
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
2014-5-8
编辑:MICHELE
2014-5-8
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
2014-5-8
What about if I change all my data input in timeseries data? Could it help solving the issues?
Geoff Hayes
2014-5-8
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
2014-5-8
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
2014-5-8
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
2014-5-8
编辑:MICHELE
2014-5-8
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
2014-5-8
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).
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Sources 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)