I have a *.m file which can read data in *.3ddose file (this is output data file from some simulation) and displays in the "Command Window" page of Matlab. Is there any way to write this displayed data into other text file?
조회 수: 1 (최근 30일)
이전 댓글 표시
function m = ReadEppOutput(file) % open the file f = fopen(file, 'rb'); % read two integers which give the size of the image size = fread(f, 2, 'int'); % initialize the output matrix m = zeros(size(1), size(2)); % read the rows into the matrix for x = 1:size(1) m(x,:) = fread(f, size(2), 'single'); end
end
댓글 수: 1
Taindra Neupane
2017년 11월 28일
I have the similar question like i have .3ddose file as an output of simulation and i want to extract that file and display either in excel,or txt ot data file for dose analysis. Help would be much appreciated. Thank you. Tain
답변 (2개)
dpb
2014년 1월 9일
function m = ReadEppOutput(file)
f = fopen(file, 'rb');
size = fread(f, 2, 'int');
Do NOT use size as a variable--that aliases the builtin Matlab function of the same name which is far too commonly used to get into such bad habits. Use something else for the variable here -- siz or sz or anything but size.
m = zeros(size(1), size(2));
% read the rows into the matrix
for x = 1:size(1)
m(x,:) = fread(f, size(2), 'single');
end
Why read the array row by row? Just read the array in one swell foop...
m=fread(f,[sz(2),inf],'single')';
f=fclose(f); % close the input file
To write it as a formatted file simply open a new file for writing and use fprintf() with appropriate formatting or one of the other higher-level i/o functions to write a csv file or however desired.
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!