Combining functions and commands in to one script
Show older comments
I have to provide a script that reads in values from 2 separate files. The script should also provide an output file for the predicted value, given the input data. So I have created 2 functions to read in the input files: flle1 and file2. I then have commands that I ran to combine the info in file1 and file2 so that the combined info from file1 and file2 can be input in to the nftool. I also have commands that I ran to modify file3 in order to use it as target data in the nftool. How do I combine this info (functions, commands, nftool data) in to one script so that I can then run this script such that another file1 and file2 can be provided to give an output file?
4 Comments
Rik
on 29 Oct 2020
Does it have to be a script? If so you will need R2016b or later, otherwise it is not possible to put functions in the same file as a script.
Sunshine
on 29 Oct 2020
Rik
on 29 Oct 2020
In that case you can put all the code you need in a single file. What exactly is the issue you are having?
Sunshine
on 30 Oct 2020
Accepted Answer
More Answers (1)
drummer
on 30 Oct 2020
You can write your pipeline as a regular script, calling your input files, processing, and obtaining your result.
As you're up-to-date with MATLAB, you can write your functions in the end of the script.
% Write your pipeline
myInputFile = myOwnReadFunction(whateverInputArguments);
% Process your data
myResults = processingData(myInputFile);
%% Below, write your functions, in the end of your script:
function data = myOwnReadFunction(input1, input2)
% code what you need
end
function result = processingData(input1)
% code your calculation
end
Cheers
11 Comments
Sunshine
on 2 Nov 2020
Rik
on 2 Nov 2020
If you want to allow your user to select a file, you should not hard-code the file name.
To ask the user to provide a file name you can use uigetfile.
Rik
on 6 Nov 2020
With this code you can ask the user to select a file. That is what you need, right?
What exactly is your question? You have already working code that uses a file name, now you know how you can ask a user for a file name.
drummer
on 6 Nov 2020
Well, you don't need to call uigetfile before the user's choice.
A minimalist approach would be like the following (idea, not code itself)
fprintf('Wanna choose files?\n');
fprintf('y or n >> ')
str = input(prompt, 's');
if str == 'y'
[file, path] = uigetfile('yourExtension');
% go through your code
else
fprintf('back off.')
end
Sunshine
on 7 Nov 2020
Sunshine
on 7 Nov 2020
Right below
ReadInFileX = uigetfile();
you can
f = msgbox({'X-Files';'Completed'}); % or something like that.
% To tell the user in a window their fileX are loaded.
Or play with
java.lang.Thread.sleep(duration*1000) % in milisec
Sunshine
on 7 Nov 2020
Sunshine
on 7 Nov 2020
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!