Too many output arguments, simple but useful question

8 vues (au cours des 30 derniers jours)
Vincent
Vincent le 2 Sep 2011
Hi, I'm trying to get the following code (simplified) running but I don't get the clue how:
a = 3; b=2; c=1;
lol = [1 2 3];
[a b c] = lol;
I get the error "Too many ouptut arguments" and I understand, that this occurs as soon as I request too many outputs from a function/expression. How may I now tell the variable "lol" to split up in 3 arguments?
(In my special case, I'm using str2double(aCellArray) instead of the variable lol)
Thanks a lot and sorry for this rather dumb question xD
  1 commentaire
Fangjun Jiang
Fangjun Jiang le 2 Sep 2011
What are you trying to do? Are you trying to assign multiple variables at a time?

Connectez-vous pour commenter.

Réponses (3)

the cyclist
the cyclist le 2 Sep 2011
Here is one kludgy way:
a = 3; b=2; c=1; lol = [1 2 3];
lolCell = num2cell(lol);
[a b c] = lolCell{:}

Grzegorz Knor
Grzegorz Knor le 2 Sep 2011
I suggest to write own function, something like this:
function varargout = split(a)
for k = 1:nargout
varargout{k} = a(k);
end
  1 commentaire
Grzegorz Knor
Grzegorz Knor le 2 Sep 2011
an example:
[a b c] = split(mean(rand(3)))

Connectez-vous pour commenter.


Vincent
Vincent le 2 Sep 2011
wow I assumed there's an easy, handsome solution. Thanks for your suggestions, I'm gonna use one of them ;)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by