Following function works as .m file but does not produce any output as function file
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2016년 5월 4일
Mehdi Gh comments "Thank you. you were right. the order in my function call was wrong!"
채택된 답변
Walter Roberson
2016년 5월 4일
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
추가 답변 (1개)
Stalin Samuel
2016년 5월 3일
The input parameters highly influence the output.So try with different input values .then you can understand the exact issue.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!