Make scalar data into a vector

조회 수: 11 (최근 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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by