从MATLAB表格中提取并显示结果
我试图从为每个力(从MATLAB表格中提取并显示结果,matlab,Matlab,我试图从为每个力(F)生成的表格中提取V的最低值,以确定最佳结果,例如,对于F=5000,V=0.06575是最佳结果。 我希望能够为F的每个实例显示此信息。我不太确定我会错在哪里 %=========================================== %This Script calculates %=========================================== %Parameter Values %F:force (N) %L1:
F
)生成的表格中提取V
的最低值,以确定最佳结果,例如,对于F=5000
,V=0.06575
是最佳结果。我希望能够为
F
的每个实例显示此信息。我不太确定我会错在哪里
%===========================================
%This Script calculates
%===========================================
%Parameter Values
%F:force (N)
%L1: Length of beam 1 (m)
%L2: Length of beam 2 (m)
%H: Height of beam 1 (m)
%h: Height of beam 2 (m)
%b: Cross section width (m)
%S: Yield strength (Pa)
%N: Factor of safety
%V:Volume of the beam (m^2)
%=========================================
clc %clear command window
clear all %clear all variables previously generated and stored in Matlab
format short g
L1=2;
L2=3;
b=0.05;
S=248;
K=1.42;
results=[];
optimalresults=[];
nd=3.6; %desired factor of safety calculated by group number
for F=5000:100:6000
for h=0.2:0.005:0.3 %loop of h
for H=0.2:0.005:0.3 % loop of H
M1=F*(L1+L2);
M2=F*L2;
I1=b*H^3/12;
I2=b*h^3/12;
Y1=H/2;
Y2=h/2;
Max_stress_1=M1*Y1/I1;
Max_stress_2=K*(M2*Y2/I2);
Max_total_stress=max(Max_stress_1,Max_stress_2);
Max_total_stress=Max_total_stress/1e6;
N=0.577*S/Max_total_stress;
%if N is greater than desired factor of safety then display results
if N >= nd
V=(b*L1*H)+(b*L2*h);
results=[results; F,V,N];sort(F);
end
end
end
results_sorted=sortrows(results,1); %sorts factor of safety from min to max
disp(' F V N');
disp(results_sorted);
optimum=results_sorted(1,:)
end
要显示每个
F
的V
最小值,我需要做哪些更改?我猜您可能希望该位位于循环的3个之外:
results_sorted=sortrows(results,1); %sorts factor of safety from min to max
disp(' F V N');
disp(results_sorted);
optimum=results_sorted(1,:)
另外,我不确定使用sort(F)实现了什么代码>在循环中。我认为您的代码需要进行两次更改,然后才能获得每个F的最小值V:
在使用sortrows的地方,应该使用第二列(V)对表进行排序,以便将最低的V放在最上面一行<代码>结果\u排序=排序(结果,2)代码>
您应该只对当前F的结果进行排序,因此您可以为每个F迭代清除变量“results”results=[]代码>或使用新变量。在对行进行排序之前,请确保检查“results”是否为空
变量“最优”现在在每个F迭代中都有最低的V。我已经将该部分移出for循环。似乎对结果没有任何影响<代码>排序(F)代码>按F(升序)对结果排序,与体积(V)或安全系数(N)相对。使查看表格时更容易确定哪一个是最佳体积。