Q:

Write a script that creates a cell array of strings, each of which is a two-word phrase. The script is to write the first word of each phrase to a file “exitstrings.dat” in the format shown below

0

Write a script that creates a cell array of strings, each of which is a two-word phrase. The script is to write the first word of each phrase to a file “exitstrings.dat” in the format shown below. You do not have to error-check on the file open or file close. The script should be general and should work for any cell array containing two-word phrases.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch9Ex25.m

strca = {'hi there', 'hello all', 'I did'}; 

outfid = fopen('exitstrings.dat','w');

for i = 1:length(strca)

 [f r] = strtok(strca{i});

 fprintf(outfid, 'Word %d: %s\n', i, f);

end

fclose(outfid);

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now