MATLAB Answers

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 views (last 30 days)
RAJESH PANTHI
RAJESH PANTHI on 9 Jan 2014
Answered: Ka Mirul on 13 May 2018
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 Comment

Taindra Neupane
Taindra Neupane on 28 Nov 2017
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

Sign in to comment.

Answers (2)

dpb
dpb on 9 Jan 2014
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 Comments

Sign in to comment.


Ka Mirul
Ka Mirul on 13 May 2018
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 .

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by