Info
This question is closed. Reopen it to edit or answer.
Assignment has more non-singleton rhs dimensions than non-singleton subscripts is produced and mistake in the array
1 view (last 30 days)
Show older comments
Hi,
I keep getting an error "Assignment has more non-singleton rhs dimensions than non-singleton subscripts is produced" which comes about due to the vectorization. To counteract that I selected each element at a time, like so:
SQAmb(i,:) = S*U(i)*(Tout-20)
Also I dont understand is the size of Ts(i) and T(i), these are supposed to come out as arrays in the form 5x5 as I am doing a loop where the temperature is subbed back in 5 times.
I think the problem is that I want to apply the Velocity (V) at each time step, so the ho and U change each time step for each surface (S), essentially what I am trying to do is to multiply the first element of S with the first element in the first column of U, and the second element of S with the first element in the second column of U and so on.
And then for the next loop the first element of S to multiply with the second element of the first column of U, and the second element of S to multiply with the second element in the second column of U and so on, but it seems I have gone wrong somewhere...if that makes any sense?
My script is below:
clc,clear
V = [1;2;3;4;5]
ho = 0.6 + 6.64.*sqrt(V)
k = [1 2 3 4 5]
lamda = [6 7 8 9 10]
hi = 2
x = (1./ho)
y = (1/hi)
z = (lamda./k)
S = [11 12 13 14 15;]
U = x + y + z
ma=1
ca=2
DTM=1
deltat=1
Tout=5
ms=1
cs=1
index=1:5;
SQAmb = zeros(numel(index), numel(S)); %Preallocation of Ambient Load (Surface) matrix
SQAmb_Tot = zeros(size(index)); %Preallocation of Total Ambient Load (Surface) matrix
QAmb = zeros(numel(index), numel(S)); %Preallocation of Ambient Load (Air) matrix
QAmb_Tot = zeros(size(index)); %Preallocation of Total Ambient Load (Air) matrix
SQTot = zeros(size(index)); %Preallocation of Total Surface Heat Load matrix
deltaTs = zeros(size(index)); %Preallocation of deltaTs matrix
Ts = zeros(size(index)); %Preallocation of Surface temperature matrix
QTot = zeros(size(index)); %Preallocation of Total Heat Load matrix
deltaTin = zeros(size(index)); %Preallocation of deltaTin matrix
Tin = zeros(size(index)); %Preallocation of car cabin temperature matrix
for i=index
if (i)==1
%Ambient Load (Surface), where 20 is the intial temperature at t=0
SQAmb(i,:) = S*U*(Tout-20)
(the first value of this array should be: the first element of S which is (11) * first element of U* temp diff (-15), this should come out to -1095.2865 but does not)
(if vectorization is used i.e. S.*U.*(Tout-20) then an error to do with "Assignment has more non-singleton rhs dimensions than non-singleton subscripts is produced")
(and if element is selected one at a time by SQAmb(i,:) = S*U(i)*(Tout-20) , the array that is formed for the Temperature at the end is not a 5x5 array)
%Total Ambient Load (Surface) in Array Form
SQAmb_Tot(i) = sum(SQAmb(i,:))
%Ambient Load (Air), where 20 is the intial air and surface temperatures at t=0
QAmb(i,:) = S*U*(20-20);
%Total Ambient Load (Air) in Array Form
QAmb_Tot(i) = sum(QAmb(i,:))
%Total Surface Heat Transfer Load
SQTot(i) = SQAmb_Tot(i)
%change in surface temperature where deltat is timestep
deltaTs(i) = (SQTot(i)/((ms*cs)+DTM))*(deltat)
%New surface temperature
Ts(i) = 20 + deltaTs(i)
%Total Heat Transfer Load
QTot(i) = QAmb_Tot(i)
%change in air cabin temperature where deltat is timestep
deltaTin(i) = (QTot(i)/((ma*ca)+DTM))*(deltat)
%New car cabin temperature
Tin(i) = 20 + deltaTin(i)
else
%Ambient Load (Surface)
SQAmb(i,:) = S*U*(Tout-(2*Ts(i-1))+Tin(i-1))
%Total Ambient Load (Surface) in Array Form
SQAmb_Tot(i) = sum(SQAmb(i,:))
%Ambient Load (Air)
QAmb(i,:) = S*U*((Ts(i-1))-Tin(i-1))
%Total Ambient Load (Air) in Array Form
QAmb_Tot(i) = sum(QAmb(i,:))
%Total Surface Heat Transfer Load
SQTot(i) = SQAmb_Tot(i)
%change in surface temperature where deltat is timestep
deltaTs(i) = (SQTot(i)/((ms*cs)+DTM))*(deltat)
%New surface temperature
Ts(i) = Ts(i-1) + deltaTs(i)
%Total Heat Transfer Load
QTot(i) = QAmb_Tot(i)
%change in air cabin temperature where deltat is timestep
deltaTin(i) = (QTot(i)/((ma*ca)+DTM))*(deltat)
%New car cabin temperature
Tin(i) = Tin(i-1)+deltaTin(i)
end
end
1 Comment
KSSV
on 5 Mar 2019
Put the code i debug mode and check dimensions.....it is due to inatilaztion problem.
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!