How do you add maximum points for both variables on the same plot as the function line?
3 ビュー (過去 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])
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Stress and Strain についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!