Just found Adi Navve's v2struct(): http://www.mathworks.com/matlabcentral/fileexchange/31532-pack---unpack-variables-to---from-structures-with-enhanced-functionality
How to write multiple variables from workspace to output structure within a function
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!