Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In matlab write a script (not a function), that uses a “while” loop to store a s

ID: 3674772 • Letter: I

Question

In matlab write a script (not a function), that uses a “while” loop to store a series of non-negative numbers entered
by the user. Each iteration of the loop will print one number to the file. Below is an example in which
the user is asked to enter ages. You may use any data and filename that you wish.
Command Window
>> problem1
Enter an age (negative to quit): 18
Enter an age (negative to quit): 29
Enter an age (negative to quit): 20
Enter an age (negative to quit): 21
Enter an age (negative to quit): -1

File contents will be:

18
29
20
21

Explanation / Answer

I have written this below matlab code to read the data using while loop condition for terminating with negtive value..

and stored the result in file..

prompt = 'Enter an age(negative to quit):';
fid=fopen('MyFile.txt','w');
while x<0
x = input(prompt)
fprintf(fid, [ x ' ']);   
end
fclose(fid);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote