MATLAB
Write a script "readFile.m" which:
a. reads a given file "file.dat" into a matrix "XYZ",
b. extracts the columns of the data from "XYZ" into arrays "c1",
"c2", ..., "cN",
c. plots some column versus another column, with a title, and
labeled axes.
To test and debug your code, create a "file.dat" with 3 rows and
N=2 columns ( so a 3×2 matrix ).
The first column should be sorted. You can just enter some
numbers in "file.dat" in an editor.
I have something like this so far
fid = fopen('file.dat');
while(~feof(fid))
line = fgetl(fid);
XYZ = fscanf(fid,'%f,%f',[3,2]);
end
fclose(fid);
clc;
XYZ = readmatrix('file.dat')
c = num2cell(XYZ,1);
figure;
hold on;
for i=1:size(XYZ,2)
plot(c{i})
end
title('plot for columns in file.dat')
xlabel('x')
ylabel('y')
file.dat
2 1
2 1
3 1
----------------------------------------------------------------------------------------------------
Your ThumbsUp on this answer matters to me a lot :)
----------------------------------------------------------------------------------------------------
Get Answers For Free
Most questions answered within 1 hours.