<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki-pnb.eri.ucsb.edu/index.php?action=history&amp;feed=atom&amp;title=File_read.m</id>
	<title>File read.m - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki-pnb.eri.ucsb.edu/index.php?action=history&amp;feed=atom&amp;title=File_read.m"/>
	<link rel="alternate" type="text/html" href="https://wiki-pnb.eri.ucsb.edu/index.php?title=File_read.m&amp;action=history"/>
	<updated>2026-04-19T14:56:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>https://wiki-pnb.eri.ucsb.edu/index.php?title=File_read.m&amp;diff=200&amp;oldid=prev</id>
		<title>128.111.101.185: Created page with '&lt;pre&gt; function [matrix,head]=file_read(file,n_Lines) % function [matrix,header]=file_read(file,n_lines) % % reads in a header of 'n_lines' from 'file' and % then reads in data to…'</title>
		<link rel="alternate" type="text/html" href="https://wiki-pnb.eri.ucsb.edu/index.php?title=File_read.m&amp;diff=200&amp;oldid=prev"/>
		<updated>2010-08-05T23:05:34Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;&amp;lt;pre&amp;gt; function [matrix,head]=file_read(file,n_Lines) % function [matrix,header]=file_read(file,n_lines) % % reads in a header of &amp;#039;n_lines&amp;#039; from &amp;#039;file&amp;#039; and % then reads in data to…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
function [matrix,head]=file_read(file,n_Lines)&lt;br /&gt;
% function [matrix,header]=file_read(file,n_lines)&lt;br /&gt;
%&lt;br /&gt;
% reads in a header of 'n_lines' from 'file' and&lt;br /&gt;
% then reads in data to 'matrix'.&lt;br /&gt;
%&lt;br /&gt;
% data must be uniform.  Number of elements in &lt;br /&gt;
% each row or column should not change.&lt;br /&gt;
&lt;br /&gt;
%cd(pb)&lt;br /&gt;
%cd('processing')&lt;br /&gt;
% open file &lt;br /&gt;
&lt;br /&gt;
	fid=fopen(file);&lt;br /&gt;
	&lt;br /&gt;
% preallocates an array for storing the header&lt;br /&gt;
% this header array may need to be adjusted &lt;br /&gt;
% if header lines exceed 70 characters.&lt;br /&gt;
&lt;br /&gt;
	head=setstr(32*ones(n_Lines,70));&lt;br /&gt;
&lt;br /&gt;
% look thru header lines&lt;br /&gt;
% store maximum line length so that header&lt;br /&gt;
% array can be streamlined.&lt;br /&gt;
	max_Line_length=0;&lt;br /&gt;
	for i=1:n_Lines,&lt;br /&gt;
		Line=fgetl(fid);length_Line=length(Line);&lt;br /&gt;
		head(i,1:length_Line)=Line;&lt;br /&gt;
		max_Line_length=max([max_Line_length,length_Line]);&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	head=head(:,1:max_Line_length);&lt;br /&gt;
&lt;br /&gt;
% read first line to determine the number of &lt;br /&gt;
% columns&lt;br /&gt;
&lt;br /&gt;
	data_start=ftell(fid);&lt;br /&gt;
	ncol=length(sscanf(fgets(fid),'%f'))&lt;br /&gt;
	fseek(fid,data_start,-1);&lt;br /&gt;
	&lt;br /&gt;
% read in rest of file as a column vector then reshape it to matrix&lt;br /&gt;
	[matrix,elements]=fscanf(fid,'%f');&lt;br /&gt;
	matrix=reshape(matrix,ncol,fix(elements/ncol))';&lt;br /&gt;
    &lt;br /&gt;
fclose(fid);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;big&amp;gt;[[file_read]]&amp;lt;big&amp;gt;&lt;/div&gt;</summary>
		<author><name>128.111.101.185</name></author>
		
	</entry>
</feed>