Clear Filters
Clear Filters

Weird problem with MATLAB misbehaving..

3 views (last 30 days)
MSP on 1 Jan 2018
Commented: Walter Roberson on 1 Jan 2018
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
if nargin == 1
lsqsize = 7;
lsqshift = 1;
elseif nargin == 2
lsqshift = 1;
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));

Answers (1)

Image Analyst
Image Analyst on 1 Jan 2018
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.
Image Analyst
Image Analyst on 1 Jan 2018
d11 is obviously different than LagR. What do you learn by stepping through with the debugger?
Walter Roberson
Walter Roberson on 1 Jan 2018
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.

Sign in to comment.


Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!