How do I call a script inside a function?
Mostra commenti meno recenti
So, I have three scrips two of them, initial_data1 and initial_data2, contain data and process it into arrays. Then I want the third scrip to run a function that uses the data from the files. I'm using matlab R2019a.
% initial_data2
dt = 0.01;
t = 0:dt:1000;
r = zeros(size(t)); %ect
The function I have works like this:
function [H,V,H_t,V_t] = Lunch_equations(data)
data;
% code
% also the output variabels are arrays if that is important.
end
And I'm trying to input the initial data files into the fuction so that the function has the local scope of one of these scrips at a time.
% The third scrip
clear
clc
[hight1,velocity1,hight_t1,velocity_t1] = Lunch_equations(initial_data1);
[hight2,velocity2,hight_t2,velocity_t2] = Lunch_equations(initial_data2);
%code
From here 'm getting an error: "Attempt to execute SCRIPT initial_data2 as a function" (or initial_data1).
Is there anyway to run the scrips inside the function as a local scope?
Thank you in advance.
Risposta accettata
Più risposte (1)
David Hill
il 1 Apr 2020
0 voti
Why not just use functions? I only use scripts when I am working in the workspace. Unless you are going to call a function more than once, you should just place the code in the original function (my opinion).
Categorie
Scopri di più su Performance and Memory in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!