DSPRelated.com
Forums

Help Loading Data

Started by Jon June 24, 2003
I have a data file that I'd really like to load into matlab because
it is very convient for me to do the analysis in matlab. Normally
between textread and load I don't have a problem doing this, but this
file contains 'random' strings every once in a while. Most of the
file is numbers (varying ammount of numbers per line) and on line 7
and about every couple hundred lines thereafter there is a line that
reads

15 ft BT dB 0.43 .161

Or something similar. Is there a way to either skip over this line
when loading it or load the line as a seperate string?



Hi,
One way is to read the data line by line and check it:
*code*
fid = fopen('filename.ext','r');
T ='';
P=[];
N=0;
while ~exist(S,'var') || S~= -1
S = fgetl(fid);
if ~isempty(findstr(S,'ft') % suppose 'ft' is typical

T = strvcat(T,[num2str(N) ' ' S]); % add to string
matrix with the line number of P
else
P1=str2num(S);
if ~isempty(P1) % avoid empty rows
N=N+1;
[P,P1] = fix_length(P,P1)
P(N,:) = P1;
end
end
end
%--------------
function [Q,L]=fix_length(Q,L)
M=size(Q,2);
M1=length(L);
if M>M1
L(M1+1:M)=NaN; % file with NaNs
elseif M<M1
Q(:,M+1:M1 = NaN;
end
*code end*

This is just one (Non-debugged) possibility. You can
improve the fix_length function to put the NaNs at
better places if you know, for example, the number of
blanks exist in place of a missing number.

I hope this helps

Joe
BSTeX- Equation viewer for Matlab
http://www.geocities.com/bstex2001

--- Jon <> wrote:
> I have a data file that I'd really like to load into
> matlab because
> it is very convient for me to do the analysis in
> matlab. Normally
> between textread and load I don't have a problem
> doing this, but this
> file contains 'random' strings every once in a
> while. Most of the
> file is numbers (varying ammount of numbers per
> line) and on line 7
> and about every couple hundred lines thereafter
> there is a line that
> reads
>
> 15 ft BT dB 0.43 .161
>
> Or something similar. Is there a way to either skip
> over this line
> when loading it or load the line as a seperate
> string? >

__________________________________