Why doesn't my code recognize my function outputs
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Whenever I try to run my code I get an error saying that survivalProb does not exist but its an output
Im trying to create a loop that codes serveral different lines but I'm only gettig one line
clear
close all
clc
% Initialize data for component
d=.005; % diameter in m
A=(pi/4)*d^2; % bolt cross-sectional area
IdealS=750000; % ideal strength in Pa
% Set load schedule
F= [10:.1:20]; % forces
%limits of each stresses
S=F./A;
% stresses
% Sample strength variability
var = [.01 .12 .04 .08]; % percent variability in strength for each batch
nSamp = [100 150 125 95]; % number of samples in each batch
for J=1:4
testStats(IdealS, var(J), nSamp(J), S);
plot(F,survivalProb,'LineWidth',4)
end
grid on
xlabel('Force Applied')
ylabel('Survival Probability')
function [survivalProb, avgSurvival] = testStats(IdealS,var,nSamp,S)
S2=S-S*var;
S1=S+S*var;
S=(S1-S2)*rand+ S2;
survivalProb= S<=IdealS;
survivalProb=double(survivalProb)
avgSurvival=sum(survivalProb,'all')/nSamp
end
0 commentaires
Réponses (1)
Star Strider
le 14 Fév 2020
Yopu code does not specifically ask for that variable.
Try this instead:
for J=1:4
[survivalProb, avgSurvival] = testStats(IdealS, var(J), nSamp(J), S);
plot(F,survivalProb,'LineWidth',4)
end
That returns both outputs.
0 commentaires
Voir également
Catégories
En savoir plus sur Stress and Strain 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!