Reputation: 15
How can I extract one of many function outputs at a time? For example, I want to receive separately the below calculations that take place within the function. But, I can't figure out why it only makes the fist calculation inside and keeps attributing the same result to the next two
W=[1 1;1 2];
w1 = matrix(W)
w2 = matrix(W)
w3 = matrix(W)
function [w1,w2,w3] = matrix(W)
w1 = trace(W)+10;
w2 = trace(W)*2;
w3 = trace(W)-1000;
end
Upvotes: 0
Views: 110
Reputation: 6863
You have to assign all the output you get from one function call, i.e.
[w1, w2, w3] = matrix(W);
Or, when you are only interested in one output, let's say the third, you can do:
[~,~,w3] = matrix(W);
Upvotes: 3