Weird problem with MATLAB misbehaving..

조회 수: 1 (최근 30일)
MSP
MSP 2018년 1월 1일
댓글: Walter Roberson 2018년 1월 1일
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

답변 (1개)

Image Analyst
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
Image Analyst 2018년 1월 1일
d11 is obviously different than LagR. What do you learn by stepping through with the debugger?
Walter Roberson
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 CenterFile Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by