Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 11-by-11.

2 views (last 30 days)
Hello, I am trying to get a plot from the following code (X,DPiE). However, there is a problem with the assignment of the elements. It works with the DPiE, in the code, but not when assigning values to X, in the code. Thank you.
%Discrete cost
PiD=20;
% Continuous cost
PiC=10;
% Penalty cost
PiP=50;
% Maximum temperature
Vmax=5;
% High temperature
Vhigh=4;
% Low temperature
Vlow=0;
% Minimum temperature
Vmin=-1;
% Time needed by the heater to heat the room per hour
Ai=2;
% Time needed for the room to cooled during one hour
A0=-4;
% Time needed to complete one leap
Dt=((Vhigh-Vlow)/Ai)-((Vhigh-Vlow)/A0);
Vtmax1=Vhigh:0.1:Vmax;
Vtlow1=Vmin:0.1:Vlow;
DpiE= zeros (length(Vtmax1),1);
X= zeros (length(Vtmax1),1);
for i=1:length(Vtlow1)
for j= 1:length(Vtmax1)
% When Vtmax==Vhigh
if (Vtlow1(i)==Vlow)&&(Vtmax1(j)==Vhigh)
%Set Vtmax and Vtlow
Vtlow=Vtlow1(i)
Vtmax=Vtmax1(j)
% Set X to "0"
x1=0;
x2=0;
x3=0;
x4=0;
X(i,j)=x1+x2+x3+x4
% Compute the time needed for the continuous cost
Vstar=Vtmax-Vtlow
%Calculate Delta t(X)
DtX=Dt+X;
%Calculate Delta Pi I
DPiI=PiD+PiC*(Vstar/Ai);
%Calculate Delta Pi I(Vstar)
DPiIX=DPiI+PiP*X;
%Calculate Delta_Pi I(Vstar)
DpiE(i,j)=DPiIX/DtX
else
Vtlow=Vtlow1(i)
Vtmax=Vtmax1(j)
% Compute X; the time taken outside the pleasant range
x1=(Vtlow-Vmin)/Ai;
x2=(Vtmax-Vhigh)/Ai;
x3=(Vhigh-Vtmax)/A0;
x4=(Vmin-Vtlow)/A0;
X(i,j)=x1+x2+x3+x4
% Compute the continuous time
Vstar=Vtmax-Vmin;
%Calculate Delta_Pi I
DPiI=PiD+PiC*(Vstar/Ai);
%Calculate Delta t(Vstar)
DtX=Dt+X;
%Calculate Delta_Pi I(Vstar)
DPiIX=DPiI+PiP*X;
%Calculate Delta_Pi E(Vstar)
DpiE(i,j)=DPiIX/DtX
end
end
end
plot (X,DpiE)
grid on
xlabel('X')
ylabel('DPiE')
end

Answers (1)

Aquatris
Aquatris on 27 Aug 2018
Here is the problem;
DpiE(i,j)=DPiIX/DtX
Both DPiTX and DTX are 11x1 vectors. When you divide 11x1 with 11x1 Matlab thinks you forgot transpose and makes it a division of 11x1 1x11 resulting in 11x11. I think you need to check what you are trying to do at that part of your code.
  2 Comments
Hamzah Faraj
Hamzah Faraj on 27 Aug 2018
Dear @Aquatris, thank you for replying. I am trying to plot DPiE and X. It has to be one line on the plot, but according to the current situation, I am going to get 11 lines instead of one, which is wrong. Is there a way to do as I am really new to MATLAB. Again, I really appreciate your help.
Aquatris
Aquatris on 27 Aug 2018
It depends on what you are trying to plot and I do not know what these calculations and variables are for. However, I will try to answer using my understanding.
You have 11 different vtlow1 values and 11 different vtmax1 values, which makes your DPiE 11x11 matrix.
Each row in the DpiE variable is calculated by different vtlow1 values and each column in the DpiE variable are calculated by different vtmax values.
So if you want to plot the values for vtlow1(index), then you can use;
plot(X,DPiE(index,:))
Similarly, if you want to plot the values for vtmax1(index);
plot(X,DPiE(:,index))
where index is from 1 to the size of the corresponding variable (11 in your code).

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!