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

| M file///C/Users/bnamp/Desktop/ICA%20MATLAB, 14 Of 14 | : Now it\'s your turn.

ID: 3604649 • Letter: #

Question

| M file///C/Users/bnamp/Desktop/ICA%20MATLAB, 14 Of 14 | : Now it's your turn. Write a function (cp.m) that takes as input the name of a text file and the name of an output file and copies the coatents f the input file to the output file. That is, cp copies text files. Hint: fprintt can print to a file (see below). From MATLAB's hel Write a short table of the exponential function to a text file called exp.txt A [x; exp(x)]; fileID fopen(.exp.txt','w'); fprintf (fileID, '36s X12sIn, 'x fclose(fileID); 'exp(x)); 2- 3 A=[x: exp (x)], % Note that A contains two rows. % fileID. fopen ('exp . txt','w'); % fprint f { fileID,"56.2f %12.8f , A); 8fclose (EileID) 1xexp(x) 2 0.00 1.00000000 3 0.10 1.10517092 4 0.20 1.22140276 0.30 1.34985881 6 0.40 1.49182470 7 0.50 1.64872127 0.60 1.82211880 9 0.70 2.01375271 10 0.80 2.22554093 11 0.90 2.45960311 12 1.00 2.71828183 10 % or you can use a loop 11tileID topen ('exp.txt' tprint (fileID,'t6s 12s ','x','exp (x)'), 12- 13- for j “ 1: length (x) 24- 15-end 16-fclose (fileiD) 17 tprintf (filero,'t6.2f 2.8f ',A(1,j),A(2, j)); 0 O o ocopy the content of a--A MATLAB R2017a . aca- SlabnEW

Explanation / Answer

clc;

prompt = 'Enter the Input File Name : ' ;

inputfile = input(prompt,'s');

prompt = 'Enter the OutPut File Name : ' ;

outputfile = input(prompt,'s');

%Open Input Text File in Read Mode

fileA=fopen(inputfile,'r');

%Read Data From File

contents = fread(fileA);

%Open Output Text File in Write Mode

fid = fopen(outputfile, 'W');

if fid == -1

disp('Cannot open file for writing.');

end

%Write Data Into File

fwrite(fid, contents);

%Close File

fclose(fid);

fclose(fileA);