How to put the output of a function into a struct?

2 views (last 30 days)
I'm given the following function to read files into Matlab:
function [VideoSignals,VideoSignals_headers,AnalogSignals,AnalogSignals_headers,AnalogFrameRate,VideoFrameRate] = read_c3d_file(fullFileName)
I want to put the output 'VideoSignals, VideoSignals_headers, AnalogSignals, AnalogSignals_headers, AnalogFrameRate and VideoFrameRate' immediately into a struct. How do I do this?
  3 Comments
Sam
Sam on 25 Dec 2014
I want to put the 6 outcomes of the function into a struct (cell 1x1).
Image Analyst
Image Analyst on 25 Dec 2014
structures and cells are different things. See the FAQ http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F Which do you want? I think structures are easier if you have a choice.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 25 Dec 2014
Just assign them:
sa.VideoSignals = VideoSignals;
sa.VideoSignals_headers = VideoSignals_headers;
sa.AnalogSignals = AnalogSignals;
sa.AnalogSignals_headers = AnalogSignals_headers;
sa.AnalogFrameRate = AnalogFrameRate;
sa.VideoFrameRate = VideoFrameRate;
You can add indexes to sa if you want to make it a structure array.
sa(k).VideoSignals = VideoSignals;
sa(k).VideoSignals_headers = VideoSignals_headers;
sa(k).AnalogSignals = AnalogSignals;
sa(k).AnalogSignals_headers = AnalogSignals_headers;
sa(k).AnalogFrameRate = AnalogFrameRate;
sa(k).VideoFrameRate = VideoFrameRate;
You can have one index, like k, or two or three or however many you need.

Tags

Community Treasure Hunt

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

Start Hunting!