0
votes

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?

1
first try adding '-ascii' to the save command. Default is some proprietary binary format, which will look like gibberish. - bdecaf
Yup, tried that, the new file is now empty. - Fahad Yunas
hmmm. '-ascii' doesn't support all data types - but shouldn't be empty. Maybe the '-struct' is problematic. Anyway, I think the fwrite solution is far more superior. So better research on that. - bdecaf

1 Answers

1
votes

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.