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!