How can I force a .txt export
古いコメントを表示
Hi,
I am working on a program that has to export .txt files, the problem is these files get named in versions as in V3.02 and then the files get saved as .02 files instead of .txt if I dont write it out every time.
is there a way to force the .txt ending?
heres my export function:
%% export
function exportSelectedCurve(fig1)
H = guidata(fig1);
p = H.params;
fs = H.fs;
t = H.t;
% --- Filter vorbereiten
[b,a] = butter(4, p.fc/(fs/2));
MA = @(x) movmean(x,p.win);
SG = @(x) sgolayfilt(x,p.order,p.framelen);
BW = @(x) filtfilt(b,a,x);
filters = {@(x)x, MA, SG, BW};
filt = filters{H.exportCurve};
% --- Daten filtern
HipZ_L = filt(H.HipZ_L + H.offset(3));
HipX_L = filt(H.HipX_L + H.offset(1));
KneeX_L = filt(H.KneeX_L + H.offset(5));
HipZ_R = filt(H.HipZ_R + H.offset(4));
HipX_R = filt(H.HipX_R + H.offset(2));
KneeX_R = filt(H.KneeX_R + H.offset(6));
% --- Outputmatrix
out = [ ...
t, ...
HipZ_L, HipX_L, KneeX_L, zeros(size(t)), ...
HipZ_R, HipX_R, KneeX_R, zeros(size(t)) ];
header = ['time,left_hip_abduction_joint,left_hip_extension_joint,' ...
'left_knee_joint,left_ankle_joint,' ...
'right_hip_abduction_joint,right_hip_extension_joint,' ...
'right_knee_joint,right_ankle_joint'];
defaultName = [H.importName '_smoothed.txt'];
% --- Save-Dialog
[file, path] = uiputfile( ...
{'*.txt','Text files (*.txt)'}, ...
'Export speichern unter', ...
defaultName);
if isequal(file,0) || isequal(path,0)
return;
end
% --- Nur .txt ergänzen, nichts abschneiden
if length(file) < 4 || ~strcmpi(file(max(1,end-3):end), '.txt')
file = [file '.txt'];
end
fname = fullfile(path, file);
% --- Datei öffnen
fid = fopen(fname, 'w');
if fid == -1
errordlg(['Datei konnte nicht geöffnet werden: ' fname], 'Exportfehler');
return;
end
% --- Header schreiben
fprintf(fid, '%s\n', header);
fclose(fid);
% --- Daten anhängen
writematrix(out, fname, 'Delimiter', ',', 'WriteMode', 'append');
disp(['Exported: ' fname]);
end
1 件のコメント
Catalytic
2026 年 3 月 8 日
We cannot run your code to see what the problem is. No input to the function is provided.
採用された回答
その他の回答 (2 件)
Instead of,
if length(file) < 4 || ~strcmpi(file(max(1,end-3):end), '.txt')
file = [file '.txt'];
end
[~,~,extension]=fileparts(file);
if ~strcmp(extension,'.txt')
file=strcat(file,'.txt');
end
Paul-William
2026 年 3 月 9 日
移動済み: Matt J
2026 年 3 月 9 日
カテゴリ
ヘルプ センター および File Exchange で Data Import and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
