Why am I not getting an array when using inverse tangent on an array in MATLAB?

In summary: Matlab function. You have to calculate each element separately.-Atan() and atan2() are both built-in functions, and they both take arrays for input arguments.
  • #1
Link-
100
0
Hi guys,

I am having a problem here with a MATLAB m.file, I am trying to take the inverse tangent of an array and expect from this function to get another array, but for some reason I don't get an array just a single number.

Any MATLAB guru that could help me with this problem?

Thanks
--link
 
Physics news on Phys.org
  • #2
arctan isn't an intrinsic matrix function. You have to calculate each element sparately.
 
  • #3
Dr Transport said:
arctan isn't an intrinsic matrix function. You have to calculate each element sparately.

Thanks for the help
 
  • #4
arctan is not a built-in Matlab function, but atan(x) and atan2(x,y) both are, and they both take arrays for input arguments.
 
  • #5
belliott4488 said:
arctan is not a built-in Matlab function, but atan(x) and atan2(x,y) both are, and they both take arrays for input arguments.

Really? Because my input was an array an I just got a single number, not an array. There's something that I could do to get an array?
 
  • #6
Link- said:
Really? Because my input was an array an I just got a single number, not an array. There's something that I could do to get an array?
Your input for which function? As I said, arctan is not built-in, so I can't guess how it would behave; that would depend on how it was written.

Here are simple examples of the other two:

Code:
>> theta = atan([.1 .2 .3 .4])

theta =

    0.0997    0.1974    0.2915    0.3805

>> theta = atan2([1 2 3 4],[10 10 10 10])

theta =

    0.0997    0.1974    0.2915    0.3805
 
  • #7
I use atan(), common I would notice if is not a built in function.

My array was stored on a variable then I tried to take the atan of the variable an expected an array.
 
  • #8
Link- said:
I use atan(), common I would notice if is not a built in function.
I don't understand this sentence.

Are you asking how to tell if a function is built-in? Use "which", as in

>> which atan

which will return the location of the function's m-file, or it might simply say that the function is a pre-compiled function, i.e. it has no m-file.

Link- said:
My array was stored on a variable then I tried to take the atan of the variable an expected an array.
You should get back an array of the same dimensions, as in this example:

Code:
>> M = [.1 .2 .3
        .4 .5 .6 ];
>> atan(M)

ans =

    0.0997    0.1974    0.2915
    0.3805    0.4636    0.5404
 
  • #9
I ran again the m-file and got the array I was looking for, maybe one of my inputs were wrong.

By that sentence that I wrote, sorry... for some reason my English is getting worse. What I tried to say is that I used atan() and not arctan, that will note by the "? Undefined command/function 'arctan'" message that is not a MATLAB function.

Thanks for the help belliott4488

-Link
 

1. What is an array function?

An array function is a type of function in programming that can perform operations on a range of values, rather than just a single value. It takes in multiple inputs and outputs a single array of values.

2. What are some common examples of array functions?

Some common examples of array functions include sorting, filtering, and mapping functions. These functions allow you to manipulate and organize data in an array without having to write complex code.

3. How do trigonometric functions work?

Trigonometric functions are mathematical functions that relate the angles and sides of a right triangle. They are commonly used in geometry and physics to solve problems involving triangles and circular motion.

4. What are the most commonly used trigonometric functions?

The most commonly used trigonometric functions are sine, cosine, and tangent. These functions represent the ratios of the sides of a right triangle and are useful in solving for unknown angles or sides.

5. How are array and trigonometric functions used in data analysis?

Array and trigonometric functions are often used in data analysis to manipulate and analyze large sets of data. They can be used to calculate averages, trends, and correlations, as well as perform advanced statistical analysis on the data.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Programming and Computer Science
Replies
17
Views
2K
Back
Top