Combining functions and commands in to one script

10 Ansichten (letzte 30 Tage)
Sunshine am 29 Okt. 2020
Kommentiert: Sunshine am 7 Nov. 2020
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 Kommentare
Sunshine am 30 Okt. 2020
I wasn't sure how to go about connecting all the info. So I was asking for some guidance. I'm trying your suggestion.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

drummer am 1 Nov. 2020
Functions by default don't show their scope variables in the workspace.
Did you have any error while running your code? If you don't, you can just perform a test by not using function in your 1st line.
So, just comment the first line of your code, and check if despx and despy appears in your workspace.
Then, your're performing the pipeline I mentioned before.
% Procedural code
% Here you call your functions
despx = importXfile('yourInput.csv')
despy = importYfile('youInput.csv')
% -------------------
%% Functions section
function x_2 = importXfile(filename, dataLines)
% function code
function y_2 = importYfile(filename, dataLines)
% function code
  3 Kommentare
drummer am 1 Nov. 2020
Bearbeitet: drummer am 1 Nov. 2020
If in the near future you want to check the scope of variables of your functions while running, you can click in the line number so it gets a red square: that's debugging stop. Your code will stop in this line, and all the variables you're creating in the environment of your function will appear in the workspace.
If you have a loop in your function for example, and you create a debug stop in the end of the loop, you can check the behavior of every related variables within the function.
If that helped, please accept the answer. =)
Good coding.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

drummer am 30 Okt. 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
function result = processingData(input1)
% code your calculation
  11 Kommentare
Sunshine am 7 Nov. 2020
After continued reading of docs, I think I figured it out. Or at least I'm not getting the error anymore. I set duration. Ha....thanks.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by