How to Plot multiple things?
    6 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
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')
0 commentaires
Réponse acceptée
  Fangjun Jiang
      
      
 le 19 Août 2011
        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 commentaires
  Fangjun Jiang
      
      
 le 19 Août 2011
				@Walter. No, not needed! figure;plot(1:100,1) shows the curve. Something I learned too!
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur 2-D and 3-D Plots 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!


