views:

74

answers:

2

Hello, 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
+1  A: 

Hi

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.

Regards

Mark

High Performance Mark
matlab is not case-sensitive with respect to the names of functions. thus if one has a function called `foobar`, one can call it as `fOoBaR` or `FOObAr`, etc. also, once one has called a function, say called `Actual_Location`, matlab interpreter will interpret `actual_location( ... )` as a call to that function, resulting in the nargin error. shame on M/W for using '()' for matrix indexing.
shabbychef
Matlab is sort-of case-sensitive. It will first look for an exact match, and then goes to check for inexact matches (throwing a warning for now, but an error in a future release).Also, () for matrix indexing is consistent, because accessing a matrix is calling a function (subsref, subsasgn) which can be overloaded.
Jonas
+1  A: 

This seems to suggest you are calling the Actual_Location function with to many arguments... I'm re-writing your code with proper indentation.

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
vicatcu

related questions