[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reading ascii files in .mat format from Ox programming language
From: |
Thomas Weber |
Subject: |
Re: Reading ascii files in .mat format from Ox programming language |
Date: |
Thu, 15 Nov 2007 12:24:02 +0100 |
Am Donnerstag, den 15.11.2007, 11:28 +0100 schrieb Riccardo Corradini:
> Hi,
> all I would like to read an ascii file like this
>
> 2 3
> 1 2 6
> 2 3 45
=====================================================================
clear all;
filename="data.dat"
[fid, msg] = fopen(filename, "r");
disp(msg)
% open the file and display any error message, if there is one
[r,c] = fscanf(fid, "%i %i", "C")
% read rows and columns
a = fscanf(fid, "%f", inf)
% read all values into the vector a; this assumes floating
% points, adapt as needed
A = reshape(a, c, r)'
% reshape the vector into a matrix; note the transpose operator
% at the end
fclose(fid);
=====================================================================
You might want to add a few tests to these lines.
Thomas