export the data of the plot to .txt or .dat file
Show older comments
I have the following code and I got a plot from the data. I wanted to export the data in the plot to .txt file or a .dat file
clear
[filename, pathname] = uigetfile('*.raw;*.prc', 'Pick raw or processed data file');
N=str2double(filename(5:6));
% load processed file
fid = fopen([pathname filename],'r','b');
A= fread(fid,inf,'*single')';
prcdata=reshape(A,N,[])';
plot((1:size(prcdata,1))./1.16E6, prcdata (:,6))
fclose(fid);
% code
end
I also tried the following
csvwrite(filename,M,'','6')
figure1 = figure;
axes1 = axes('Parent',figure1)
hold(axes1,'all');
plot((1:size(prcdata,1))./1.16E6, prcdata (:,6))
saveas(figure1,'finename.jpg') % here you save the figure
title(strrep(filename,'Time','Amplitude'))
Accepted Answer
More Answers (1)
Image Analyst
on 12 Oct 2015
Well, neither of those two chunks of code does anything at all like writing the array to a text file! Try this:
filename = 'My Output file.txt'; % Whatever
fid = fopen(filename, 'wt');
if fid ~= -1
fprintf('%f\n', prcdata(:,6)); % Write out column 6 of prcdata.
fclose(fid);
else
message = sprintf('Could not open file %s for writing', filename);
uiwait(warndlg(message));
end
11 Comments
Annonymous User
on 13 Oct 2015
Image Analyst
on 13 Oct 2015
Well, yeah. You plotted prcdata's column 6. You said you wanted what you plotted to go into a text file. So, the code does that. Why do I need to give another suggestion when it does exactly what you asked for. Did you also want the x values on each line of hte text file in addition to the y values?
Annonymous User
on 13 Oct 2015
Annonymous User
on 13 Oct 2015
Image Analyst
on 13 Oct 2015
Edited: Image Analyst
on 13 Oct 2015
x = (1:size(prcdata,1)) ./ 1.16E6;
xy = [x(:), prcdata(:,6)];
fprintf('%f, %f\n', xy); % Write out column 6 of prcdata.
Annonymous User
on 13 Oct 2015
Image Analyst
on 13 Oct 2015
Yes, put those 3 lines instead of the single fprintf() from before.
Annonymous User
on 13 Oct 2015
Annonymous User
on 13 Oct 2015
Image Analyst
on 13 Oct 2015
It should not take that long unless you have hundreds of gigabytes of data.
Annonymous User
on 28 Oct 2015
Categories
Find more on Data Import and Export in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!