Matlab functions not interacting with main program.
信息
此问题已关闭。 请重新打开它进行编辑或回答。
显示 更早的评论
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
0 个评论
回答(1 个)
Star Strider
2020-4-11
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.
.
0 个评论
此问题已关闭。
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!