How to get a single value of an array through a function inside a script?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Zahid Saleem
am 8 Mai 2019
Bearbeitet: Stephen23
am 9 Mai 2019
Hello,
I have two questions, how can we use a variable defined in a script to be used later inside a function in the same script?
2nd, I am having trouble in trying to get a single value of an array which is processed inside a function inside a script. The function should return the u'th value of the array gE by storing it in the Eg(function return) but I get an error of
Index exceeds matrix dimensions.
Error in Slab_002>Esrc (line 187)
Eg = gE(u);
How can we fix this? All answers are welcome.
script something something
a = something;
gE = zeros(1, something);
dt = something;
STEPS = something;
function Eg = Esrc(u)
a = dt*u; %% I want to use the a that is defined above in the code.
for i = 1:STEPS
gE(i) = exp(-((t-t0-a)/tau).^2);
end
Eg = gE(u);
end
0 Kommentare
Akzeptierte Antwort
Kevin Phung
am 8 Mai 2019
function Eg = Esrc(u,a)
a = dt*u; %% I want to use the a that is defined above in the code.
for i = 1:STEPS
gE(i) = exp(-((t-t0-a)/tau).^2);
end
Eg = gE(u);
end
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!