how to save variable as txt in a specified location with variable value appearing in the file name
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rabih Sokhen
am 24 Nov. 2021
Beantwortet: Mathieu NOE
am 24 Nov. 2021
clear all
clc
a=1; % amplitude du faisceau gaussien
x=linspace(-50,50,100);
dx=50/2.355; % widthn
f=a*exp(-0.5*(x./dx).^2);
[pks, locs, width]=findpeaks(f,x)
plot(x,f)
path='c:/users/user/desktop';
save('Gauss',num2str(width),'.txt', 'f','-ascii')
hello guys
i want to save My "f" variable as a txt file in the path location and i want to name the following file as Gauss.value of width.txt
i tried the following code but i get a error:
error using save '47.7723' is not a valid variable name
error in line 10
thank you in advance for your help
0 Kommentare
Akzeptierte Antwort
Chunru
am 24 Nov. 2021
a=1; % amplitude du faisceau gaussien
x=linspace(-50,50,100);
dx=50/2.355; % widthn
f=a*exp(-0.5*(x./dx).^2);
[pks, locs, width]=findpeaks(f,x)
plot(x,f)
% don't use "path" as a variable name
% path='c:/users/user/desktop';
folder = ''; % Modify this
save(fullfile(folder, 'Gauss.txt'), 'f', '-ascii')
type Gauss.txt
0 Kommentare
Weitere Antworten (2)
KSSV
am 24 Nov. 2021
path='c:/users/user/desktop';
filename = [path,filesep,'Gauss',num2str(width),'.txt'];
fid = fopen(filename,'w') ;
fprintf(fid,'%f\n',f);
fclose(fid) ;
0 Kommentare
Mathieu NOE
am 24 Nov. 2021
hello
try with (last two lines)
f = f';
save(['Gauss' num2str(width) '.txt'], 'f','-ascii')
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!