Filter löschen
Filter löschen

How to make smooth curve

1 Ansicht (letzte 30 Tage)
Mahome
Mahome am 17 Jul. 2017
Kommentiert: Jan am 17 Jul. 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 Kommentar
Jan
Jan am 17 Jul. 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"?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Smoothing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by