Question
I would like to determine several target positions in the Z direction (height). 10 values are to be determined, Gaussian distributed around the value 80, with a standard deviation of 40 and a repetition of the drawing for a value of <0 and >160. I thank you for any help and suggestions!
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 26, 2026
Z=randn(10,1)*40+80; isOK=all(iswithin(Z,0,160)); while ~isOK % regenerate code here depending on what your definition of "regeneration" is Z=randn(10,1)*40+80; isOK=all(iswithin(Z,0,160)); end
The above regenerates a whole new sample; with these parameters the frequency of failing the test is only 5%. If the number of trials gets to be extremely large this might be an observable slowdown, but for simplicity it's hard to beat other than just truncating the values outside the range. Oh... iswithin is my "syntactic sugar" routine
function flg=iswithin(x,lo,hi) % returns T for values within range of input % SYNTAX: % [log] = iswithin(x,lo,hi) % returns T for x between lo and hi values, inclusive flg= (x>=lo) & (x<=hi); >>
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related gaussian Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →