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 Import and Export에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!