lab4.m - Lab 4 Your name Sofiane Mansouri fname ='lab4_test_output fileID = fopen(fname'w Get a timestamp for this test fprintf(fileID'This test starts

lab4.m - Lab 4 Your name Sofiane Mansouri fname...

This preview shows page 1 - 2 out of 3 pages.

%% Lab 4 % Your name: Sofiane Mansouri % fname = 'lab4_test_output.txt'; fileID = fopen(fname, 'w'); % Get a timestamp for this test fprintf(fileID, 'This test starts at %s\n', datetime('now')); % Q1 (10%) *********************************** if (~exist('fileID')) fileID = fopen('lab4_test_output.txt', 'w'); end fprintf(fileID, '*****Q1: for loop:\n'); % Write a for loop to output the following lines to above created file. % Value of the cv: 11 % Value of the cv: 12 % Value of the cv: 13 % Value of the cv: 14 % Value of the cv: 15 % Hint: % Name the for loop's control variable to be "cv", % and loop the command fprintf(fileID, 'Value of the cv: %i\n', cv); % Write your answer here: %% Q2 ************************************* R(1) = 243; for i=2:5 R(i) = R(i-1)*(1/3); end %% The above for loop creates a geometric sequence R with a common ratio 1/3. % Convert the for loop to a while loop and generate the same geometric sequence. if (~exist('fileID')) fileID = fopen('lab4_test_output.txt', 'w'); end fprintf(fileID, '\n*****Q2: while loop, geometric sequence:\n'); % Write your answer here: % Output to the test file fprintf(fileID, 'R = [ '); fprintf(fileID, '%d ', R); fprintf(fileID, ']'); fprintf(fileID, '\n'); %% Q3(10%) ***********************************
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 3 pages?

  • Spring '08
  • MinooAminian

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors