Make scalar data into a vector

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 个)

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 个评论

In other words,
common_values = a(a==b);
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

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

产品

版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by