To create a script, use the edit
command,
edit plotrandLoops and Conditional Statements
Within a script, you can loop over sections of code and conditionally execute sections using the keyWords
for
,while
,if
, andswitch
.Now, modify the
for
loop so that you can view the results at each iteration.Display text in the Command Window that includes the current iteration number, and remove the semicolon from the assignment tosampleMean
.for k = 1:nsamples iterationString = ['Iteration #',int2str(k)]; disp(iterationString) currentData = rand(npoints,1); sampleMean(k) = mean(currentData)endoverallMean = mean(sampleMean)
新闻热点
疑难解答