Following function works as .m file but does not produce any output as function file
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mehdi Gh
am 3 Mai 2016
Kommentiert: Walter Roberson
am 4 Mai 2016
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 Kommentare
Walter Roberson
am 4 Mai 2016
Mehdi Gh comments "Thank you. you were right. the order in my function call was wrong!"
Akzeptierte Antwort
Walter Roberson
am 4 Mai 2016
Your intervals are too small. In
timing = [end_span+begtime+sindent:sindent:end_span+stinterval end_span+stinterval+bindent:bindent:end_span+btinterval]';
begtime+sident > stinterval and stinterval+bindent > btinterval so no matter how far along you shift the end_span, the end point is before the beginning point and so the interval is empty.
2 Kommentare
Weitere Antworten (1)
Stalin Samuel
am 3 Mai 2016
The input parameters highly influence the output.So try with different input values .then you can understand the exact issue.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!