MATLAB: Read ascii non-delimited file

fixed-formatnon-delimitedread

How do I read a numeric non-delimited file in matlab program? I tried using
fid=fopen('filename','r')
this generated fid=-1 and then textscan does not work.
Load function does not work on non-delimited files.
Is there any other way to read such file?
Here is an example how my data file looks –
-99.9999-99.9999-99.9999-99.9999 -1.2828 -1.2812
-1.0910 -1.1864 -1.2920-99.9999-99.9999-99.9999
-99.9999-99.9999-99.9999-99.9999-99.9999-99.9999
Thanks in advance!

Best Answer

I know it's not too fancy, but it's really simple, so how about:
fid = fopen('vacube.dat')
entireLine = fgetl(fid); % Read first line.
row = 1;
while ischar(entireLine)
fprintf('Line %d = "%s"\n', row, entireLine);
% Parse out the 6 numbers from the 48 character long string.
numbers(row, 1) = str2double(entireLine(1:8));
numbers(row, 2) = str2double(entireLine(9:16));
numbers(row, 3) = str2double(entireLine(17:24));
numbers(row, 4) = str2double(entireLine(25:32));
numbers(row, 5) = str2double(entireLine(33:40));
numbers(row, 6) = str2double(entireLine(41:48));
% Get the next line (if any).
entireLine = fgetl(fid);
row = row + 1; % Increment row counter for the numbers array.
end
fclose(fid); % Close the file.
% Report the numbers to the command line.
numbers
It looks like it's pretty similar to dpb's.