フィルターのクリア

Saving signal as a text file

22 ビュー (過去 30 日間)
John Smith
John Smith 2015 年 11 月 20 日
コメント済み: Guillaume 2015 年 11 月 21 日
Hi. I am having problems saving a signal as a text file. Let's assume we have the signal below, how can I save xt as a text file with the first column representing the time the second column representing the amplitude?
Fs = 8000; % samples per second
Ts = 1/Fs; % seconds per sample
t = 0: Ts: 3; % Start signals at 0sec and stop after 3sec
% Sine wave x1[n]:
Fc = 1;
x1 = sin(2*pi*Fc*t);
% Sine wave x2[n]:
Fc = 760;
x2 = sin(2*pi*Fc*t);
% Sine wave x3[n]:
Fc = 1280;
x3 = sin(2*pi*Fc*t);
% Sine wave x4[n]:
Fc = 2000;
x4 = sin(2*pi*Fc*t);
xt = x1 + x2 + x3 + x4;

採用された回答

Image Analyst
Image Analyst 2015 年 11 月 20 日
How about making it a csv file:
filename = 'deleteme.csv' % Whatever you want.
csvwrite(filename, [t', xt']);
type(filename) % type to command window.
%delete(filename); % Delete the file.

その他の回答 (2 件)

Guillaume
Guillaume 2015 年 11 月 20 日
編集済み: Guillaume 2015 年 11 月 20 日
One simple way:
t = table(t', xt', 'VariableNames', {'Time', 'Amplitude'});
writetable(t, 'somefile.txt');
  2 件のコメント
John Smith
John Smith 2015 年 11 月 20 日
Thanks for the reply, it worked. Is it possible to save just the data values? I removed {'Time', 'Amplitude'}, but it did not work. Also, how can I replace the commas between the columns with blank spaces?
Guillaume
Guillaume 2015 年 11 月 21 日
A quick look through the documentation of writetable would have answered both questions:
writetable(t, 'somefile.txt', 'WriteVariableNames', false, 'Delimiter', ' ');

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


Image Analyst
Image Analyst 2015 年 11 月 20 日
If you want no header and a space between the numbers, use this:
filename = 'deleteme.csv' % Whatever you want.
dlmwrite(filename, [t', xt'], 'delimiter', ' ');
type(filename) % type to command window.
  1 件のコメント
John Smith
John Smith 2015 年 11 月 20 日
Thanks it worked. I replaced .csv with .txt to save it as text file.

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

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by