Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matrix as output of a function

Maybe a very easy question, but I am already looking for hours on the Internet for the answer but I cannot find it.

I have created the function below. In another m-file I want to use the matrix 'actual_location'. However, it is not possible to use an individual cell of the matrix (i.e. actual_location(3,45) or actual_location(1,2)). When I try to use an individual cell, I get the following error : ??? Error using ==> Actual_Location Too many input arguments.

Can anyone please tell me what I have to change, so that I can read individual cells of the matrix?

function [actual_location] = Actual_Location(~);  
actual_location=zeros(11,161);
for b=1:11  
   for t=1:161  
       actual_location(b,t) = (59/50)*(t-2-(b-1)*12)+1;   
       if actual_location(b,t) < 1  
           actual_location(b,t) =1;  
       end       
   end  
   actual_location(1,1)  
end
like image 700
Daan Avatar asked Nov 05 '22 17:11

Daan


1 Answers

As you have defined it, the name in the m-file for the matrix written by your function Actual_Location is actual_location. However, when you call your function you can give the output any name you like. I presume that you are calling it like this, remembering that Matlab is a bit case-sensitive:

actual_location = Actual_Location(arguments);

You are just writing to confuse yourself. Use a name other than actual_location for the dummy argument in the function definition, and call the function to return to a variable with a more distinct name, something like this:

output = Actual_Location(arguments);

It appears that you may be expecting actual_location(1,1) to return element 1,1 of an array, whereas it is, probably, a function call with 2 input arguments.

like image 170
High Performance Mark Avatar answered Nov 15 '22 08:11

High Performance Mark