.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개)
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
댓글 수: 10
Dhyrim
2017년 5월 3일
KL
2017년 5월 3일
did you try dlmread? It's much easier and direct.
Dhyrim
2017년 5월 3일
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
2017년 5월 3일
Dhyrim
2017년 5월 3일
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
2017년 5월 4일
편집: John Kelly
2017년 11월 10일
Dhyrim
2017년 5월 4일
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
