How do you add maximum points for both variables on the same plot as the function line?

1 次查看(过去 30 天)
I need to plot deflection vs load on a graph. I understand this, and got this to work, but i am supposed to plot the max of each variable on the same graph, and when i try to do this, the entire graph goes blank, showing nothing just the title axis labels and grid. This is my code, can someone please help: the second part is about stress and strain so please ignore that part of the code.
D = [0:0.1:1.4]/200;
L = [0 1 2 3 4 5 6 6.8 6.5 6 5.5 5.4 5.3 5.25 5.22]*1000;
%calculating the deflection and load
Deflection = [0:0.01:1.4]/200;
Load = spline(D,L,Deflection);
Load = Load+rand(size(Load));
maxDeflection = max(Deflection);
maxLoad = max(Load);
crossSecArea = 0.000015;
Stress = Load * crossSecArea;
Strain = ((Deflection-0.1)/0.1);
UltStress = maxLoad * crossSecArea;
engineeringStrain = ((Deflection-0.1)/0.1);
linearStress = Stress(2:65);
linearStrain = Stress(2:65);
YM = linearStress./linearStrain;
youngsModulus = mean(YM);
figure(1)
handle_a = plot(Deflection,Load);
set(handle_a,'linewidth',1.5);
%plot(maxLoad,'marker','*','markersize',10);
%plot(maxDeflection,'marker','o')
hold on
handle_x = xlabel('Deflection [m]');
set(handle_x,'fontname','times','fontsize',16)
handle_y = ylabel('Load [N]');
set(handle_y,'fontname','times','fontsize',16)
handle_title = title('Deflection vs Load');
set(handle_title,'fontname','times','fontsize',20)
grid on
axis([0 0.0071 0 7000])

回答(1 个)

Christiaan
Christiaan 2015-3-15
编辑:Christiaan 2015-3-15
Dear Jess,
For your first figure, you forgot the command "hold on". Also if you want to add two markers, you do not only need the y value, but also the x value. You can find the corrected code below:
clc;clear all;close all;
D = [0:0.1:1.4]/200;
L = [0 1 2 3 4 5 6 6.8 6.5 6 5.5 5.4 5.3 5.25 5.22]*1000;
%calculating the deflection and load
Deflection = [0:0.01:1.4]/200;
Load = spline(D,L,Deflection);
Load = Load+rand(size(Load));
[maxDeflectiony maxDeflectionx] = max(Deflection);
x_Defl_max = Deflection(maxDeflectionx);
y_Defl_max = Load(maxDeflectionx);
[maxLoady maxLoadx] = max(Load);
x_Load_max = Deflection(maxLoadx);
y_Load_max = Load(maxLoadx);
crossSecArea = 0.000015;
Stress = Load * crossSecArea;
Strain = ((Deflection-0.1)/0.1);
UltStress = maxLoady * crossSecArea;
engineeringStrain = ((Deflection-0.1)/0.1);
linearStress = Stress(2:65);
linearStrain = Stress(2:65);
YM = linearStress./linearStrain;
youngsModulus = mean(YM);
figure(1)
handle_a = plot(Deflection,Load);
set(handle_a,'linewidth',1.5);hold on;
plot(x_Load_max,y_Load_max,'-.r*','MarkerSize',10,'MarkerFaceColor',[.49 1 .23]);hold on
plot(x_Defl_max,y_Defl_max,'-.go','MarkerSize',5,'MarkerFaceColor',[.49 1 .63]);hold off
handle_x = xlabel('Deflection [m]');
set(handle_x,'fontname','times','fontsize',16)
handle_y = ylabel('Load [N]');
set(handle_y,'fontname','times','fontsize',16)
handle_title = title('Deflection vs Load');
set(handle_title,'fontname','times','fontsize',20)
grid on
axis([0 0.0071 0 7000])
Good luck! Christiaan

类别

Help CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by