Effacer les filtres
Effacer les filtres

Multiple vector output in a function

2 vues (au cours des 30 derniers jours)
Agent Cooper
Agent Cooper le 20 Juin 2014
Commenté : Agent Cooper le 20 Juin 2014
I am trying to define a function that returns two vectors.
function [X, Y] = element_select(A,B,astart,astep,bstart,bstep)
X = A(astart:astep:numel(A));
Y = B(bstart:bstep:numel(B));
end
For example, let's consider A = [1 2 3 4 5], B = [6 7 8 9 10], astep = 1, bstep = 2 and astart = bstart = 1. I would like the answer to be two different vectors X = [1 2 3 4 5] and Y = [6 8 10]. Instead, I get only one vector ans = [1 2 3 4 5].
Could anyone, please, give me a hint on how to solve this?

Réponse acceptée

W. Owen Brimijoin
W. Owen Brimijoin le 20 Juin 2014
You need to specify that you want both outputs:
[X,Y] = element_select(A,B,astart,astep,bstart,bstep)
X =
1 2 3 4 5
Y =
6 8 10
  1 commentaire
Agent Cooper
Agent Cooper le 20 Juin 2014
Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by