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

2 views (last 30 days)
jess ferguson on 15 Mar 2015
Edited: Christiaan on 15 Mar 2015
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;
Deflection = [0:0.01:1.4]/200;
maxDeflection = max(Deflection);
crossSecArea = 0.000015;
Strain = ((Deflection-0.1)/0.1);
engineeringStrain = ((Deflection-0.1)/0.1);
linearStress = Stress(2:65);
linearStrain = Stress(2:65);
YM = linearStress./linearStrain;
youngsModulus = mean(YM);
figure(1)
set(handle_a,'linewidth',1.5);
%plot(maxDeflection,'marker','o')
hold on
handle_x = xlabel('Deflection [m]');
set(handle_x,'fontname','times','fontsize',16)
set(handle_y,'fontname','times','fontsize',16)
set(handle_title,'fontname','times','fontsize',20)
grid on
axis([0 0.0071 0 7000])

Christiaan on 15 Mar 2015
Edited: Christiaan on 15 Mar 2015
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;
Deflection = [0:0.01:1.4]/200;
[maxDeflectiony maxDeflectionx] = max(Deflection);
x_Defl_max = Deflection(maxDeflectionx);
crossSecArea = 0.000015;
Strain = ((Deflection-0.1)/0.1);
engineeringStrain = ((Deflection-0.1)/0.1);
linearStress = Stress(2:65);
linearStrain = Stress(2:65);
YM = linearStress./linearStrain;
youngsModulus = mean(YM);
figure(1)
set(handle_a,'linewidth',1.5);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)
set(handle_y,'fontname','times','fontsize',16)
set(handle_title,'fontname','times','fontsize',20)
grid on
axis([0 0.0071 0 7000])
Good luck! Christiaan