Filter löschen
Filter löschen

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

4 Ansichten (letzte 30 Tage)
Sam
Sam am 25 Dez. 2014
Beantwortet: Image Analyst am 25 Dez. 2014
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 Kommentare
Sam
Sam am 25 Dez. 2014
I want to put the 6 outcomes of the function into a struct (cell 1x1).
Image Analyst
Image Analyst am 25 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 25 Dez. 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.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by