简体   繁体   中英

how to extract outputs from function in Matlab?

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

You have to assign all the output you get from one function call, ie

[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); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM