[Matlab] Load line of vector separately(From matrix file)

Status
Not open for further replies.

davyzhu

Advanced Member level 1
Joined
May 23, 2004
Messages
494
Helped
5
Reputation
10
Reaction score
2
Trophy points
1,298
Location
oriental
Activity points
4,436
Hello all,

I have a file contain several lines of vectors(all the digit is in ASCII mode).
The file's content is like below, each line is a vector(something like
you use SAVE -ascii to save a matrix):
1 2 3 4 5 6 7 8 9 10
6 7 8 9 10 1 2 3 4 5
4 5 6 7 8 1 2 3 9 10
... ...
But my real vector each line is 1*2000, and I have 4000 lines vectors(i.e. a 4000*2000 matrix).
So the vector is too large to load all the vectors(i.e. the file matrix) by LOAD -ascii command.

How to load each line of vector separately?
i.e. load line1 vector -> load line2 vector -> ...till the last line vector

In all, I want a loop that reads one line from the file per loop iteration.

Thanks!
Richard
 

What's wrong with doing this?
foo = load('mydata');

That works fine with a file containing 2000x4000 numbers. The resulting matrix of doubles consumes 64 megabytes.

If that's not what you want, please explain better "load each line of vector separately".
 

Hi echo47,

I am confused with this operation ;-)

Loading the matrix consumes too many ram. And load all the matrix is not necessary for my job.

Each line of the matrix is a codeword received from the channel. So I have to decode a codeword each time(Not necessary load all the codeword).

So what I want is dealing with rows of the matrix(i.e. the row vector of the matrix).

For example,
at time1, load the row 1 from matrix file, decode the code word 1;
at time2, load the row 2 from matrix file, decode the code word 2;
... ...

Sorry for my poor English,

Best regards,
Davy
 

Re: [Matlab] Load line of vector separately(From matrix file

Ahhh ... read one line per loop iteration!

Is this what you have in mind?

Code:
fin = fopen('mydata');
while ~feof(fin)
  foo = sscanf(fgetl(fin), '%d', [1 inf]);
  disp(foo);    % replace this with your line parsing code
end
fclose(fin);
 

    davyzhu

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…