Change from file=input to no input required

1 次查看(过去 30 天)
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'])

采纳的回答

Bhavik Patel
Bhavik Patel 2021-5-20
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 个)

类别

Help CenterFile Exchange 中查找有关 Software Development Tools 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by