Fahad Yunas
Fahad Yunas

Reputation: 1

Resave imported data with same header lines in matlab

Good day,

I am importing a text data file into matlab 'Old_file.p2m'

The data file has the first two lines as a header, as shown below:

data Set
Rx    X(m)   Y(m)   RSS(dBm)
1      10      20     -76.71
2      15      20     -76.64
3      20      20     -76.57

So I am using the following code to import the data:

filename =('Old_file.p2m'); tmp = importdata(filename,' ',2);

Which specifies that the first two are header lines and reads the data into a 1x1 struct 'tmp'.

Now, I have the first 2 header lines in tmp.textdata and the remaining numeric data in column format in tmp.data

My question is that after I modify a column of tmp.data, how can I resave the modified struct into another file New_file.p2m with the same header file appended on top of it (basically the same format as the Old_file.p2m).

I tried using:

save('New_file.p2m','-struct','tmp');

but the newly saved file New_file.p2m is unreadable gibberish.

Any suggestions?

Upvotes: 0

Views: 146

Answers (1)

Vuwox
Vuwox

Reputation: 2359

Have a look to fwrite. This function allow you to right data in the order you want, and maybe you can do your loading with fread as well.

Upvotes: 1

Related Questions