Are there two conditions at once when using the if condition?
1 次查看(过去 30 天)
显示 更早的评论
Hello. I have a question and am posting.
I solved it as below, but the value I want is not found, so I ask. Q_1 is entered only when tact is 1 and k is 1, and I am trying to calculate the rest by putting the rest in the expression.
So, when tact is 1 and k is 1, can't we just put the value of Q_1?? For the rest, I try to use the formula below.
Q_1 = 30;
Q_D = 11.3;
Q_E = 8.3;
Q_R = 7.5;
Q_F = 4.5;
connection_D = [1,0,0,0; 0,1,0,0; 0,0,1,0; 0,0,0,1];
connection_E = [0,1,0,0; 0,0,1,0; 0,0,0,1; 1,0,0,0];
connection_F = [0,0,1,0; 0,0,0,1; 1,0,0,0; 0,1,0,0];
connection_R = [0,0,0,1; 1,0,0,0; 0,1,0,0; 0,0,1,0];
for tact = 1:4
for k=1:4
if k==1
Q_column(1)=Q_1
else
Q_column(k) = Q_column(k-1) + Q_D*connection_D(tact,k) - Q_E*connection_E(tact,k) + Q_F*connection_F(tact,k) - Q_R*connection_R(tact,k)
end
end
end
回答(1 个)
Prince Kumar
2022-1-25
Hi,
Q_1 = 30;
Q_D = 11.3;
Q_E = 8.3;
Q_R = 7.5;
Q_F = 4.5;
connection_D = [1,0,0,0; 0,1,0,0; 0,0,1,0; 0,0,0,1];
connection_E = [0,1,0,0; 0,0,1,0; 0,0,0,1; 1,0,0,0];
connection_F = [0,0,1,0; 0,0,0,1; 1,0,0,0; 0,1,0,0];
connection_R = [0,0,0,1; 1,0,0,0; 0,1,0,0; 0,0,1,0];
for tact = 1:4
for k=1:4
if k==1 & tact == 1
Q_column(1)=Q_1
else
Q_column(k) = Q_column(k-1) + Q_D*connection_D(tact,k) - Q_E*connection_E(tact,k) + Q_F*connection_F(tact,k) - Q_R*connection_R(tact,k)
end
end
end
You can use any combination of operators as per your need.
Hope this helps.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!