export the data of the plot to .txt or .dat file

19 ビュー (過去 30 日間)
Annonymous User
Annonymous User 2015 年 10 月 12 日
コメント済み: Annonymous User 2015 年 10 月 28 日
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'))

採用された回答

Walter Roberson
Walter Roberson 2015 年 10 月 13 日
x = (1:size(prcdata,1))./1.16E6;
y = prcdata;
xy = [x(:), y(:)];
dlmwrite('YourOutputFile.txt', xy, 'delimiter', ',');
  5 件のコメント
Annonymous User
Annonymous User 2015 年 10 月 13 日
thank you walter and Image analyst will test this out
Annonymous User
Annonymous User 2015 年 10 月 13 日
This code worked it took almost an hour to analyse the data and export it.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 10 月 12 日
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 件のコメント
Image Analyst
Image Analyst 2015 年 10 月 13 日
It should not take that long unless you have hundreds of gigabytes of data.
Annonymous User
Annonymous User 2015 年 10 月 28 日
the data I had was around 6GB that too had 5 files each... so took almost 2 days to write the whole thing into a file thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by