Why doesn't my code recognize my function outputs

3 ビュー (過去 30 日間)
Kathryn Pacheco
Kathryn Pacheco 2020 年 2 月 14 日
回答済み: Star Strider 2020 年 2 月 14 日
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

回答 (1 件)

Star Strider
Star Strider 2020 年 2 月 14 日
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.

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by