MATLAB: Export the data of the plot to .txt or .dat file

.dat.prcexport datagraphplottxt

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'))

Best Answer

x = (1:size(prcdata,1))./1.16E6;
y = prcdata;
xy = [x(:), y(:)];
dlmwrite('YourOutputFile.txt', xy, 'delimiter', ',');