Following function works as .m file but does not produce any output as function file
Mostra commenti meno recenti
Hello,
The following code works prefectly when run as .m file but when I want to use it as a function its output is empty!
function timespan= timesep(begtime,endtime,stinterval,btinterval,sindent,bindent)
% clearvars
% begtime=0;
% endtime=115;%
% stinterval = 5;%
% btinterval=20;%
% sindent = 1;%
% bindent = 5;%
time_span = [begtime]; end_span = 0;
for iter = 1:fix(endtime/btinterval)
timing = [end_span+begtime+sindent:sindent:end_span+stinterval end_span+stinterval+bindent:bindent:end_span+btinterval]';
time_span = [time_span; timing]; % (1:end-1)
end_span = iter*btinterval;
end
if mod(endtime,btinterval)
timing = [end_span+begtime+sindent:sindent:end_span+stinterval end_span+stinterval+bindent:bindent:endtime]';
time_span = [time_span; timing];
end
timespan = time_span;
end
To use it as function I run
tspan=timesep(0,200,1,5,5,20);
but tspan is empty!
Explanation of what the code does: It takes a range and divide it to different intervals. however the intervals are smaller at specific ranges and bigger at the rest. This is like having different time-steps when solving a numerical problem where at some points due to numerical instabilities time-steps should be very small, but at other points can be big to increase the computational speed.
3 Commenti
CS Researcher
il 3 Mag 2016
Give it the same values as you give to your script and then compare.
tspan = timesep(0, 200, 5, 60, 0.0001, 0.01)
Mehdi Gh
il 4 Mag 2016
Walter Roberson
il 4 Mag 2016
Mehdi Gh comments "Thank you. you were right. the order in my function call was wrong!"
Risposta accettata
Più risposte (1)
Stalin Samuel
il 3 Mag 2016
0 voti
The input parameters highly influence the output.So try with different input values .then you can understand the exact issue.
Categorie
Scopri di più su Function Creation 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!