Effacer les filtres
Effacer les filtres

Multiple outputs for the same function

2 vues (au cours des 30 derniers jours)
fiona rozario
fiona rozario le 11 Fév 2017
Commenté : fiona rozario le 12 Fév 2017
I am using a function in my code whose output needs to be assigned to different variables as per the input variable that I pass to the function.
Eg: Output needs to be 'ersh1' when I pass 'rsh1' in the function call and should be 'ersh2' when I pass 'rsh2' in the function call.
I tried giving a generic output name like 'eshare' in the function definition but the code gave an error of index mismatch. When I changed it to 'ersh1', it was successful.
Will I have to have multiple copies of the same function so that I can assign a different output to it? I need to use the function 6 times, each time assigned to a different variable...

Réponse acceptée

Image Analyst
Image Analyst le 11 Fév 2017
Why can't you just do
ersh1 = YourFunction(rsh1);
ersh2 = YourFunction(rsh2);
ersh3 = YourFunction(rsh3);
ersh4 = YourFunction(rsh4);
ersh5 = YourFunction(rsh5);
ersh6 = YourFunction(rsh6);
  1 commentaire
fiona rozario
fiona rozario le 12 Fév 2017
It worked...thanks. I must have made some error the last time it didn't work.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by