Matlab functions not interacting with main program.
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
I can't change an array I have in my main program correctly. When I print the content using "Arrprint" my original [1 2 3 4 5] array is printed, not the one that I've changed to [1 9 3 4 5]. Does it only create a local array inside my functions that is not put back into the original array?
Main program:
A=[1 2 3 4 5];
Arrchange(A);
Arrprint(A);
Arrchange:
function A = Arrchange(A)
A(2)=9;
end
Arrprint:
function A = Arrprint(A)
disp(A);
end
Réponses (1)
Star Strider
le 11 Avr 2020
Your function works correctly.
You need to return the changed ‘A’ to your workspace (I call it ‘Ac’ here):
A=[1 2 3 4 5];
Ac = Arrchange(A)
Arrprint(Ac)
That will produce the result you want.
.
Cette question est clôturée.
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!