Thread Subject: Selecting the output argument of a function

Subject: Selecting the output argument of a function

From: Salvador Gomez

Date: 30 Oct, 2009 17:31:03

Message: 1 of 2

Hello, I am trying to do something that seems quite simple, but I can't find the way to do it.
I have two vectors with several values, x and y and I want to do something to a vector depending on the value of r (r is the radius value after converting x and y to polar). In other words I would like to do something "like" (the command below does not work, but it will show what I want to do):
vector((cart2pol(x,y)[2])>5)=0
The problem is that "r" is the second output argument given by cart2pol and not be selected with the command above. Any idea about what could I do?
Thanks a lot for your help.
Salva

Subject: Selecting the output argument of a function

From: Carlos Adrian Vargas Aguilera

Date: 30 Oct, 2009 18:12:04

Message: 2 of 2

Interesting, but I guess that cannot be done in a single MATLAB line. Neither you can call an specific element of the first output!

% Let's see:
x = [1 2];
y = [2 3];
[a,b] = cart2pol(x,y);
% returns
% a = [1.1071 0.9828]
% b = [2.2361 3.6056]

% You can't get the a(2) with
cart2pol(x,y)(2) % error

% And much less you can't get the full b:
cart2pol(x,y)[2] % error

Anyway, by the way, as far as I know, when you call a function withing another one, the first output is only called:
sum(cart2pol(x,y))
% is equal to
sum(a)

Anybody?

carlos

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
output Salvador Gomez 30 Oct, 2009 13:34:03
argument Salvador Gomez 30 Oct, 2009 13:34:03
function Salvador Gomez 30 Oct, 2009 13:34:03
rssFeed for this Thread

Contact us at files@mathworks.com