.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

Respuestas (1)

KL
KL el 3 de Mayo de 2017
Editada: KL el 3 de Mayo de 2017

0 votos

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 comentarios

Dhyrim
Dhyrim el 3 de Mayo de 2017
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.
KL
KL el 3 de Mayo de 2017
did you try dlmread? It's much easier and direct.
Dhyrim
Dhyrim el 3 de Mayo de 2017
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...
KL
KL el 3 de Mayo de 2017
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.
Dhyrim
Dhyrim el 3 de Mayo de 2017
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.
Dhyrim
Dhyrim el 3 de Mayo de 2017
KL
KL el 4 de Mayo de 2017
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 el 4 de Mayo de 2017
Editada: John Kelly el 10 de Nov. de 2017
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.
Dhyrim
Dhyrim el 4 de Mayo de 2017
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
KL
KL el 4 de Mayo de 2017
that's surprising. I created my own dat file with few values of similar precision and the import works fine.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 3 de Mayo de 2017

Editada:

el 10 de Nov. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by