필터 지우기
필터 지우기

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