Combining functions and commands in to one script
古いコメントを表示
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 件のコメント
Rik
2020 年 10 月 29 日
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
2020 年 10 月 29 日
Rik
2020 年 10 月 29 日
In that case you can put all the code you need in a single file. What exactly is the issue you are having?
Sunshine
2020 年 10 月 30 日
採用された回答
その他の回答 (1 件)
drummer
2020 年 10 月 30 日
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 件のコメント
Sunshine
2020 年 11 月 2 日
Rik
2020 年 11 月 2 日
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
2020 年 11 月 6 日
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
2020 年 11 月 6 日
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
2020 年 11 月 7 日
Sunshine
2020 年 11 月 7 日
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
2020 年 11 月 7 日
Sunshine
2020 年 11 月 7 日
カテゴリ
ヘルプ センター および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!