Make scalar data into a vector

8 ビュー (過去 30 日間)
Ting Florence
Ting Florence 2022 年 1 月 26 日
コメント済み: Ting Florence 2022 年 1 月 26 日
for i=1:length(x)
a(i)=round(-19.93984628*x(i).^2-19.26822854*x(i)+28.63259561);
%Use inverse matrix to form system curve equation
totalX1=sum(X1);
totalY1=sum(Y1);
totalA=sum(X1.*Y1);
totalB=sum(X1.^2);
totalC=sum(X1.^3);
totalD=sum(X1.^4);
totalE=sum(X1.^2.*Y1);
n=length(X1);
A1=[n totalX1 totalB;totalX1 totalB totalC;totalB totalC totalD];
B1=[totalY1;totalA;totalE];
S1=A1\B1;
b(i)=round(S1(3)*x(i).^2+S1(2)*x(i)+S1(1));
if a(i)==b(i)
fprintf(fid,'\n\nFor Single Pump\n');
fprintf(fid,'------------------\n');
fprintf(fid,'The Operating point is at Q=%.3fm3/s\n\n',x(i));
RQ=0.7; %Requested flow rate
end
end
the above is my coding. What I would like to ask for help is: how can I make the 'x' values (scalar) when 'if a(i)==b(i) into a vector? there were multiple output for x values but i want to compile them into a vector.
Hope can help.

回答 (1 件)

KSSV
KSSV 2022 年 1 月 26 日
a(i)==b(i) gives a logical output i.e. either 0 or 1. If a and b are vectors a == b, gives a logical vector as output having 1 and satisfied location and 0 at condition not satisfied. To check you can use
any(a==b)
  2 件のコメント
Walter Roberson
Walter Roberson 2022 年 1 月 26 日
In other words,
common_values = a(a==b);
Ting Florence
Ting Florence 2022 年 1 月 26 日
I think I am wanna to compile scalar output into one vector, not to check whether they are vector... or i need to check my variable one by one? haha

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by