Effacer les filtres
Effacer les filtres

How to make smooth curve

1 vue (au cours des 30 derniers jours)
Mahome
Mahome le 17 Juil 2017
Commenté : Jan le 17 Juil 2017
Hi I have been trying for awhile to make a smooth curve instate of linear curve for my written script, but I've not gotten any kind of positive result .. I used spline, and polyfit did not work perfectly with mine, the matlab keep given me linear curve!. Let me share with you my codes
clc, clear all
disp(['The simulation requires to fill out the value of requirments'...
'of concepts']);
d=5;
h=10;
y_i=7;
y_s=5;
dt=30;
band =1;
v_in =100;
v_out =60;
% convert gallon per minutes to ft^3/s & rate it to be step every dt
v_inn = (v_in /448.831)*dt; v_outt=(v_out/448.831)*dt;
% volume equation
volume = @(current_hight) (d/2)^2*pi* current_hight;
% low band & high band
band_low= y_s - (1/2 *band); band_high= y_s + (1/2 *band);
% Possibilities
if volume(y_i) > volume(h) || volume(y_i) < volume(y_s)
error('The amount of fluid is exceed the size of tank')
end
if v_out > v_in
error(['The amount of outlet fluid is greater than inlet fluid,'...
' will not able to fill the tank'])
end
current_volume = volume(y_i); n= 2;
out(1,1)=current_volume;
for i = volume(y_i): - v_outt : (volume(band_low))
current_volume = current_volume - v_outt;
out(n,1)=current_volume; n=n+1;
if current_volume <= volume(band_low)
while current_volume < volume(band_high)
current_volume = current_volume + v_inn - v_outt;
out(n,1)=current_volume; n= n+1;
end
end
end
time = [0: dt : (length(out)-1)*dt];
water_level = out/((d/2)^2*pi);
hold on; box on; xlabel('Time(s)'); ylabel('Water Level (ft)');
title('On/Off Control Simulation');
axis([time(1) time(end) band_low*0.75 band_high*1.5]);
plot(time, water_level, '-ok','LineWidth',1);
plot(time, ones(length(out),1).*band_high,'-b','LineWidth',4);
plot(time, ones(length(out),1).*y_s, '-y','LineWidth',2);
plot(time, ones(length(out),1).*band_low,'-r','LineWidth',4);
legend ('Fluid Path Simulation', 'Upper Band','Setpoint','Lower Band')
hold off
I would from
plot(time, water_level, '-ok','LineWidth',1);
to be a smooth curve line instate of linearly plot.
Thank you
  1 commentaire
Jan
Jan le 17 Juil 2017
I recommend to post the relevant code only. It is not clear what you mean by "smooth". The line has a sawtooth shape, so how coulöd it be "smoothed"? What did you try by "spline" or "polyfit"?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Smoothing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by