Example 1
Back to Index
% Script File: eg1
%
% Reading data from a file and displaying it with a
% crude plot.
%
% Keywords: fopen, fscanf, plot3, title, sprintf, size.
% This particular file's name is 1.CRD.
fid = fopen('1.CRD');
% The format of the file is to have 3 floating point numbers
% per line.
% The %g format is used to read in each entry.
% The data is to be stored in a matrix A.
% Each file input line becomes a column in the matrix A.
% We do not know a priori how many lines there are, so the
% [3 inf] keeps the reading process going until the end of
% the file is reached.
A = fscanf(fid,'%g %g %g',[3 inf]);
% Assign the number of rows in A to m and the number of
% columns to n.
[m,n] = size(A);
% The location of the kth amino acid is
%
% (A(1,k),A(2,k),A(3,k))
%
% Let's connect these dots in 3-space in order and put
% a title on the plot.
plot3(A(1,:),A(2,:),A(3,:))
title(sprintf('There are %2d amino acids in this chain.',n))
Q1. Modify the script so that the first and last amino acid are highlighted with a red asterisk.