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?

3 次查看(过去 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
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
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

Ka Mirul
Ka Mirul 2018-5-13
Hi, I think that at the first step you have to read the data to matlab variable first. I've write matlab code to read specific line of .3ddose data. You can read the tutorial here and download the code here .

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by