Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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!

Réponse acceptée

Matt H
Matt H le 11 Avr 2017

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by