이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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 (한국어)