Make scalar data into a vector

9 visualizaciones (últimos 30 días)
Ting Florence
Ting Florence el 26 de En. de 2022
Comentada: Ting Florence el 26 de En. de 2022
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.

Respuestas (1)

KSSV
KSSV el 26 de En. de 2022
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 comentarios
Walter Roberson
Walter Roberson el 26 de En. de 2022
In other words,
common_values = a(a==b);
Ting Florence
Ting Florence el 26 de En. de 2022
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

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by