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

  • Context: MATLAB 
  • Thread starter Thread starter Link-
  • Start date Start date
  • Tags Tags
    Array Functions Trig
Click For Summary

Discussion Overview

The discussion revolves around a user's issue with obtaining an array output when using the inverse tangent function in MATLAB. The focus is on the correct usage of functions for array inputs, specifically addressing the confusion between 'arctan' and 'atan'.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant reports an issue where using the inverse tangent on an array results in a single number instead of an array.
  • Some participants clarify that 'arctan' is not a built-in MATLAB function, suggesting that element-wise calculations are necessary.
  • Others point out that 'atan' and 'atan2' are the correct built-in functions that can handle array inputs.
  • A participant shares examples demonstrating the expected output of 'atan' when applied to an array.
  • The original poster later acknowledges using 'atan' instead of 'arctan' and indicates that they received the expected array output after re-running their code.

Areas of Agreement / Disagreement

While there is agreement on the fact that 'atan' is the appropriate function for arrays, the initial confusion regarding 'arctan' and the circumstances leading to the single number output remain unresolved.

Contextual Notes

Participants discuss the importance of using built-in functions correctly and the potential for user error in inputting data. The discussion does not resolve the specifics of the user's initial problem.

Who May Find This Useful

Users seeking clarification on MATLAB functions, particularly those related to trigonometric calculations and array handling.

Link-
Messages
99
Reaction score
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
arctan isn't an intrinsic matrix function. You have to calculate each element sparately.
 
Dr Transport said:
arctan isn't an intrinsic matrix function. You have to calculate each element sparately.

Thanks for the help
 
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.
 
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?
 
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
 
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.
 
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
 
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
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
7K
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K