Weird problem with MATLAB misbehaving..
1 次查看(过去 30 天)
显示 更早的评论
This is the Linear regression function. My problem is when I am running one line using this function MATLAB2017a returns values but when this function is inside another function it does not run leading to error. Pls have a look at the attached snap
function [a1,a0] = linreg(x,lsqsize,lsqshift)
error(nargchk(1,3,nargin)) % # INPUTS BET'N 1 AND 3
% DEFAULT VALUES
if nargin == 1
lsqsize = 7;
lsqshift = 1;
elseif nargin == 2
lsqshift = 1;
end
num_col = fix((size(x,1) - lsqsize + lsqshift)/lsqshift);
num_row = size(x,2);
for k = 1:num_col
for l = 1:num_row
loc = (k-1)*lsqshift+1;
[a1(k,l),a0(k,l)] = lsqfit(x(loc:loc+lsqsize-1,l));
end
end
end
0 个评论
回答(1 个)
Image Analyst
2018-1-1
Put these lines as the first two lines inside your linreg() function:
a0 = []; % Initialize to null.
a1 = []; % Initialize to null.
Then set a breakpoint at this line
[a1(k,l),a0(k,l)] = lsqfit(x(loc:loc+lsqsize-1,l));
and then try to figure out why your code execution never ever reaches that line of code and so a1 never gets assigned at all.
3 个评论
Image Analyst
2018-1-1
d11 is obviously different than LagR. What do you learn by stepping through with the debugger?
Walter Roberson
2018-1-1
In your code being called within the function, either num_row or num_col is coming out as 0 because of the data you pass in.
I note by the way that you are calling LinReg but your function name is linreg . MATLAB is case sensitive; however, the name of the file overrides the name given on the function line.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!