.dat file editing

Hi, I need help with some beginner lvl stuff in matlab. I have a .dat file, with 3 colums of long data, that I want to use in another program for research. I would like to open the file, and multiply/add every value of the first column with a fixed number. Then after the values are changed, i would want to save it under a new name, but still as a .dat file, so I can use it outside of matlab. Can anyone help me with this? Thx in advance

回答(1 个)

KL
KL 2017-5-3
编辑:KL 2017-5-3
data_in = dlmread('sample.dat');
data_out = [data_in(:,1)*2, data_in(:,2)+4, data_in(:,3)];
save my_data.dat data_out -ASCII
check here

10 个评论

Thx, it is not working yet, I get an error
'Mismatch between file and format string. Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> fid = fopen('var-rrd.dat', 'r');\n'
I suspect that this does cant read the numbers, because all the data is in this form:
2.456894305223933887e+06 1.586189550781250000e+04 1.004255390167236328e+01 1.329731140136718750e+02 ....
So I think the 'e+01' notation needs to be converted somehow. Im also unsure on how to do this.
did you try dlmread? It's much easier and direct.
yes, that was the one I used like you said. But I think it can only read in numbers, and it doesnt think 2.456894305223933887e+06, for example is a number. At least I think that is what is going wrong...
That is a number. Say your dat file looks like
2.456894305223933887e+06 1.586189550781250000e+04
1.004255390167236328e+01 2.456894305223933887e+06
...
and you should be able to read them without any problems. Attach the a sample dat file and m file with what you have tried, then maybe it's easier to understand.
This site did not allow me to atach a .dat file. I do have a screenshot of how it looks like in notepad.
Maybe I could send the file to your email if you want?
As for the code, I used the exact same m-file as you made basicallyl I just changed the file names ofc.
I see from the screenshot, for example, in the 1st row, there's no delimiter between 4th and 5th column. Your dat file is not properly formatted.
Where do you get your dat file from? If it's some other software, try and export it properly there.
Dhyrim
Dhyrim 2017-5-4
编辑:John Kelly 2017-11-10
Well from my prof., a research group made these .dat files I believe, and the data in it is from NASA. If they messed up, then im definitely going to mess up to, haha.
Its kinda working, I imorted the data and then saved it using the line you proposed. Only problem is, now it saves the numbers in their short form, it cuts it of after a certain decimal.... and I also used format long
that's surprising. I created my own dat file with few values of similar precision and the import works fine.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Standard File Formats 的更多信息

提问:

2017-5-3

编辑:

2017-11-10

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by