Modify the script from the previous problem. Assume that the data file is in exactly that format, but do not assume that the number of lines in the file is known. Instead of using a for loop, loop until the end of the file is reached
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:9| Question number:13.9
All Answers
total answers (1)
Ch9Ex13.m
%Read data points from "xypts.dat" and plot
fid = fopen('xypts.dat');
if fid == -1
disp('File open not successful')
else
%Initialize counter variable
i = 0;
while feof(fid) == 0
aline = fgetl(fid);
%Separate each line into two parts: x and y
[x, rest] = strtok(aline,'y');
x(1:2) = []; %Removes the "x" and the space
[let, y] = strtok(rest);
i = i + 1;
xvec(i) = str2num(x);
yvec(i) = str2num(y);
end
plot(xvec,yvec,'ko')
xlabel('x')
ylabel('y')
title(sprintf('Number of data points: %d',i))
%Error-check file close
closeresult = fclose(fid);
if closeresult == 0
disp('File close successful')
else
disp('File close not successful')
end
end
Medical organizations store a lot of very personal information on their
patients. There is an acute need for improved methods of storing,
sharing, and encrypting all of these medical records. Being able to
read from and write to the data files is just the first step.
need an explanation for this answer? contact us directly to get an explanation for this answer