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일

0 개 추천

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

Dhyrim
Dhyrim 2017년 5월 3일
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 2017년 5월 3일
did you try dlmread? It's much easier and direct.
Dhyrim
Dhyrim 2017년 5월 3일
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 2017년 5월 3일
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 2017년 5월 3일
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 2017년 5월 3일
KL
KL 2017년 5월 4일
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.
Dhyrim
Dhyrim 2017년 5월 4일
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 2017년 5월 4일
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