Weird problem with MATLAB misbehaving..
2 ビュー (過去 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168361/image.png)
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!