フィルターのクリア

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

1 回表示 (過去 30 日間)
Matt H
Matt H 2017 年 4 月 11 日
回答済み: Matt H 2017 年 4 月 11 日
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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by