How to Plot multiple things?

Hi, For some reason when I run this code I can't get the plot(re_m, c_d, 's', re_m, f, '-',[0:.01:3], 0.5, 'r-') right. Does anyone know why? Thanks in advance. Here is my code
% case 1
w_speed = [1; 1.1; 1.5; 2.5; 3; 4; 4.3; 5; 5.9; 6.1]; %in mph
d_force = [.05; .06; .09; .1; .11; .15; .21; .25; .3; .35]/10
w_speed = w_speed*0.44704 % converts mph to meters per second
speed_force=[w_speed d_force] % wind speed and its corresponding drag force
% USV DATA
l_usv = 0.45; % lenght of usv (metric)
w_usv= .18; % width of usv
h_usv = .09; % height of usv
% NAVY BOAT DATA
l_boat = 12; % length of the navy boat in m
v_boat = 5; % velocity of the boat m/s
% for air at atmospheric pressure and T = 25 degrees centigrade we have:
ro = 1.184; % air density in kg/m^3
mu = 1.849*(10^-5); % air viscosity in kg/m.s
% calculating drag coeff and reynolds number for the model
a = w_usv*h_usv;
c_d = 2*d_force./(ro*(w_speed.^2)*a) % drag Coeff
re_m = ro*w_speed*w_usv/mu % reynolds number
subplot(2,1,1)
p1 = polyfit(w_speed, d_force, 1); % returns 2 coefficients fitting r = a_1 * x + a_2
r2 = p1(1).* w_speed + p1(2);
plot(w_speed, d_force, 's', w_speed, r2)
xlabel 'Wind Speed (m/s)'
ylabel 'Drag Force (N)'
legend ('Measured data', 'Best fit curve')
subplot(2,1,2)
p2= polyfit(re_m, c_d, 6);
f = polyval(p2,re_m);
% table = [re_m c_d f c_d-f]
plot(re_m, c_d, 's', re_m, f, '-',[0:.01:3], 0.5, 'r-')
%plot([0:.01:3], 0.5, 'r-')
xlabel 'Reynolds number'
ylabel 'C_D'
legend ('Measured data', 'Best fit curve')

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 8월 19일

0 개 추천

check the value of re_m. It's much larger than [0:.01:3]. That's why you didn't see the red line. Try:
figure;
plot(re_m, c_d, 's', re_m, f, '-',[0:.01:3]*1e4, 0.5, 'r-')

댓글 수: 3

Villanova
Villanova 2011년 8월 19일
Thank you very much Fangjun. I just noticed what I had been wrong since this morning. You are a life saver!
Walter Roberson
Walter Roberson 2011년 8월 19일
Also, you might have to make 0.5 to be same size as the [0:.01:3]
Fangjun Jiang
Fangjun Jiang 2011년 8월 19일
@Walter. No, not needed! figure;plot(1:100,1) shows the curve. Something I learned too!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by