Write a script that will read x and y data points from a file, and will create an area plot with those points. The format of every line in the file is the letter ‘x’, a space, the x value
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:12| Question number:2.12
All Answers
total answers (1)
Ch12Ex2.m
% Read x and y coordinates of points from a data file
% and plot them using an area plot
x = [];
y = [];
fid = fopen('xandypts.dat');
if fid == -1
disp('File open not successful')
else
while ~feof(fid)
aline = fgetl(fid);
[letter, rest] = strtok(aline);
[xval, rest] = strtok(rest);
[letter, rest] = strtok(rest);
yval = strtok(rest);
x = [x str2num(xval)];
y = [y str2num(yval)];
end
area(x,y)
title(sprintf('%d data points',length(x)))
fclose(fid);
end
need an explanation for this answer? contact us directly to get an explanation for this answer