Change from file=input to no input required
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mariano Negron Perez
am 12 Mai 2021
Kommentiert: Mariano Negron Perez
am 20 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
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!
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Software Development Tools 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!