0
votes

I am having a bit of problem with calling my functions within my nested for loops and was wondering if anyone could figure it out...

new_location = 50x2 matrix of cell locations * 0.1

B = 150x150 matrix of rand vals

for j = 1:numel(new_location(:,1)) 
    for k = 1:numel(new_location(:,2))
    if new_location(j + 1) - new_location(j) < 0.3
       final_location = check_intensity(B(j),B(j + 1),new_location(j),new_location(j + 1));
    else if new_location(k + 1) - new_location(k) < 0.3
       final_location = check_intensity_2(B(k),B(k + 1),new_location(k),new_location(k + 1));
        else
            ;
        end
    end
    end
end

User-defined functions:

function final_location = check_intensity(B(j),B(j + 1),new_location(j),new_location(j + 1))
if B(j) > B(j + 1)
    final_location(j) = new_location(j);
else
    final_location(j) = new_location(j + 1);
end

My error is simply saying:

Error: File: check_intensity.m Line: 1 Column: 44 Unbalanced or unexpected parenthesis or bracket.

Error in coord_1_sb (line 36) final_location = check_intensity(B(j),B(j + 1),new_location(j),new_location(j + 1));

1

1 Answers

2
votes

That is because you are supposed to enter input argument names in that position. So check_intensity(B(j),B(j + 1),new_location(j),new_location(j + 1)) is basically correct when you are calling the function & not when defining the function. The right way is to use simple variable names while defining the function, like check_intensity(x,y,new_loc1,new_loc2). That should solve your problem. So your User Defined function would look like this

function final_location = check_intensity(x,y,new_loc1,new_loc2,j)
    if x > y
        final_location = new_loc1;
    else
        final_location = new_loc2;
    end