Change from file=input to no input required

1 Ansicht (letzte 30 Tage)
Mariano Negron Perez
Mariano Negron Perez am 12 Mai 2021
Good afternoon,
I have a matlab code which requires user input every time I run it, and I run it so much that by now I always just input "1" as the name for the files; how can I alter this code so it saves to those files without user input? i.e. my input is always "1".
-----------------------------------------------------------------------------------------------------------------------------------------------------------
%File name to store data, e.g. 'myfile' or 'temp' or 'sardata'.
file=input('Enter root file name for data and listing files: ','s');
...
data_file=[file,'.mat'];
mystery_file=[file,'_mys.mat'];
listing_file=[file,'.lis'];
eval(['save ',data_file,' c tau W fs s Npulses PRF PRI T_out fc', ...
' Ta v lambda Rc u Rcrp Ls DR DCR Ntargets coords y t_y Nr txLFM txtotal rxSig SNR_radar_dB RCRdB Rs SRBR']);
eval(['save ',mystery_file,' c tau W fs s Npulses PRF PRI T_out fc', ...
' Ta v lambda Rc u Rcrp Ls DR DCR y t_y Nr txLFM txtotal rxSig SNR_radar_dB RCRdB Rs SRBR']);
fid=fopen(listing_file,'w');
...
fclose(fid);
fprintf(['\n\nData is in file ',data_file])
fprintf(['\nStudent data is in file ',mystery_file])
fprintf(['\nListing is in file ',listing_file,'\n\n'])

Akzeptierte Antwort

Bhavik Patel
Bhavik Patel am 20 Mai 2021
It is my understanding that you want to freeze the value of a variable instead of requesting it from a keyboard.
Since you want to apply the same value to file variable in your code, replace the first line of your code with this:
file = '1'; % Specify a character vector as file name
Hope this helps!

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by