필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Sam
Sam 2014년 12월 25일
답변: Image Analyst 2014년 12월 25일
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
Sam
Sam 2014년 12월 25일
I want to put the 6 outcomes of the function into a struct (cell 1x1).
Image Analyst
Image Analyst 2014년 12월 25일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2014년 12월 25일
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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by