# Math Help - MATLAB - Need some help with errors

1. ## MATLAB - Need some help with errors

I got this M-File and I need to look for the errors (theres 4 of them) for the file to function properly

Code:
function [c,d]=errors(x)

%This function file generates a matrix d of which the elements
%are the elements of x minus 1. At the same time it generates a
%value c indicating how often the function file has gone through
%the second for loop.

[p,q]=size(x)
for a=1:q
for b=1:p
d(a,b)=x(a,b)-1;
c=c+1;
end

2. Originally Posted by Kevlar
I got this M-File and I need to look for the errors (theres 4 of them) for the file to function properly

Code:
function [c,d]=errors(x)

%This function file generates a matrix d of which the elements
%are the elements of x minus 1. At the same time it generates a
%value c indicating how often the function file has gone through
%the second for loop.

[p,q]=size(x)
for a=1:q
for b=1:p
d(a,b)=x(a,b)-1;
c=c+1;
end
Have you checked the red and/or amber marks in the right margin of the Matlab editor window?

Have you tried running this on a non-square random matrix?

How about in the debugger?

I am closing this thread, since any further assistance with this will defeat the purpose of the exercise, which is for you to debug this code.

CB