When a structure is passed to a function, can we add a field to it?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohamed Abd El Raheem
le 20 Jan 2022
Commenté : Mohamed Abd El Raheem
le 21 Jan 2022
As the title suggests:
If I passed a structure variable to a function, can this function add a new field to it and have that stucture among its outputs with the new added field?
Or, do I have to create a new output structure?
0 commentaires
Réponse acceptée
Voss
le 20 Jan 2022
Modifié(e) : Voss
le 20 Jan 2022
The answer is yes, the function can add a new field and pass the struct back out, and no, you don't have to create a new struct (MATLAB creates a new struct for you).
input = struct('old_field',1);
output = test_function(input);
disp(input);
disp(output);
function in = test_function(in)
in.new_field = 2;
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown 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!