How to create a new matrix from an function performed on another matrix?

Hi, say I have a 5x1 matrix of complex numbers
V=[1+0i;
3+4i;
2+3i;
0;
4+3i];
And I wish to create a new 5x1 matrix "Theta" that has the angles of each element in it.
I was able to come up with:
Theta = [rad2deg(angle(V(1,1)));rad2deg(angle(V(2,1)));rad2deg(angle(V(3,1)));rad2deg(angle(V(4,1)));rad2deg(angle(V(5,1)));];
but Im wondering if theres a more straightforward, compact way to do it. I tried with arrayfun but I couldn't get it to work
Thank you

 Accepted Answer

Many functions in MATLAB will just accept a matrix:
V=[1+0i; 3+4i; 2+3i; 0; 4+3i];
Theta = rad2deg(angle(V))
ans = 5×1
0 53.1301 56.3099 0 36.8699

1 Comment

Thank you just as I read this I figured it out with array func: Theta = arrayfun(@(x) rad2deg(angle(x)),V);
but I was just overcomplicating things

Sign in to comment.

More Answers (0)

Products

Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!