%fplot.m

%Read data from a file
[x,y]=textread('filename.txt');

%Plot the 'filename.txt' data
plot(x,y,'b')%b=blue, no markers will be used since none specified

hold on

%Use dlmread (out text file we know has two columns of data)
C=dlmread('filename2.txt');
%Get number of rows
n2=size(C,1);%First number in size command for C will be the row
%Input first column of C into x2, second column of C into y2
x2=C(1:n2,1);
y2=C(1:n2,2);

%Plot the 'filename2.txt' data
plot(x2,y2,'kd-')%k=black, d=diamond shaped marker

%Use textscan
formatSpec3 = '%f %f';%In this case floating point numbers
    %Specify the file ID
    fileID3 = fopen('filename3.txt','r');    
    %Read the data and put it in a variable
    D=textscan(fileID3,formatSpec3);%Notice transpose used here
    %Put contents of D into x3, and y3
    x3=D{1};%first column of D
    y3=D{2};%second column of D
    
%Plot the 'filename3.txt' data
plot(x3,y3,'mo-')%m=magenta,o=round circle marker

%Read data from a file using fscanf
    %Specify format of data you expect to read from file
    formatSpec4 = '%f %f \n';%In this case floating point numbers
    %Specify the file ID
    fileID4 = fopen('filename4.txt','r');
    %Specify the size data in file
    sizeB=[2 Inf];
    %Read the data and put it in a variable
    B=fscanf(fileID4,formatSpec4,sizeB)';%Notice transpose used here
    %Put the first column of B into x4
    n4=size(B,1);%get number of rows for matrix B
    x4=B(1:n4,1);%Matlab allows us to grab all rows of column 1 here
    %Put the second column of B into y4
    y4=B(1:n4,2);%Matlab allows us to grab all rows of column 2 here
    %Close the file to read the data
    fclose(fileID4);
        
%Plot the 'filename4.txt' data
plot(x4,y4,'rv-')%r=red, v=triangle marker

%Create Legend
legend('filename.txt','filename2.txt','filename3.txt','filename4.txt','location','southeast')

    