How to write multiple variables from workspace to output structure within a function

1 次查看(过去 30 天)
Hello, I'm stuck somewhere between Python and Matlab, and I'm trying to figure out if this is possible. I would like to be able to write multiple workspace variables to a structure 'output', so they could be used later. In this example, there are only three (a,b,c), but in the real code, there may be 1-2 dozen things I would like to have access to for debug and report generation.
function [value,output] = getValue(var)
var.a = 1;
var.b = 5;
var.c = 12;
value = var.a + var.b + var.c;
% output = ?;
The closest thing I could find was struct(), where:
var2struct = @(x) struct(inputname(1),x)
a = 1;
output = var2struct(a)
>>output =
>>a: 1
However, I'd like to be able to pass structure element(s) all to the same output structure. Any thoughts would be much appreciated. Thanks!

采纳的回答

Matt H
Matt H 2017-4-11

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by