Matlab functions not interacting with main program.
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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
Antworten (1)
Star Strider
am 11 Apr. 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.
.
Diese Frage ist geschlossen.
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!