Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
Sam
Sam le 25 Déc 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 commentaires
Sam
Sam le 25 Déc 2014
I want to put the 6 outcomes of the function into a struct (cell 1x1).
Image Analyst
Image Analyst le 25 Déc 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.

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 25 Déc 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.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by