Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fwrite and matrix data

Subject: fwrite and matrix data

From: Kurt

Date: 29 Aug, 2010 13:58:04

Message: 1 of 2

Hi,

In my application I generate a large number of possible routes (consisting of trip numbers). E.g.
Route 1: [5 21 30 5]
Route 2: [5 21 33 6 28 40]

As the number of possible routes is very large, it is impossible for me to keep them in one single matrix, as I get an out of memory error. Therefore per set of routes, I want to write them to disk. Currently I'm trying to periodically write a subset of routes to a binary file (one file to hold all the routes). However, upon reading the generated route file, the information on what item is in what row (thus route) seems to be lost as I use fread (for the above example):
5
5
21
21
30
33
5
6
28
40

Is there any way to reconstruct the above routes from the binary file? I also use fwrite to store them to a .txt file but that is twice as slow and speed is a key issue.

Thanks,
Kurt

Subject: fwrite and matrix data

From: Walter Roberson

Date: 29 Aug, 2010 15:04:40

Message: 2 of 2

On 29/08/10 8:58 AM, Kurt wrote:
> Currently I'm
> trying to periodically write a subset of routes to a binary file (one
> file to hold all the routes). However, upon reading the generated route
> file, the information on what item is in what row (thus route) seems to
> be lost as I use fread

> Is there any way to reconstruct the above routes from the binary file?

No. Binary files do not have any inherent concept of rows or lines.

You will need to impose structure on the binary data as you write it,
such as outputting an element count just before you write the elements
for a route, or outputting a value that cannot possibly otherwise appear
in your data (e.g., a negative "route number") as a marker of the end of
an individual route. With either a count or a delimiter, you can
reconstruct the individual "rows".

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us