What is the difference between structure and table?

조회 수: 30 (최근 30일)
SangMin
SangMin 2018년 10월 20일
댓글: Walter Roberson 2019년 12월 12일
For me, they looks very similar. I'm not sure when I should use table or structure.
Structure
Table

채택된 답변

Walter Roberson
Walter Roberson 2018년 10월 20일
편집: Walter Roberson 2019년 12월 12일
table has a nicer output presentation, and should be more efficient in memory. It also has some useful operations especially when you start getting into timetable objects.
table makes it easier to select subsets of the data. For example you might want to select the excitation and fft of all the entries on a particular date. With struct you would do something like construct mask to select particular structure entries and then do
out = struct('excitation', S(mask).excitation, 'fft', S(mask).fft);
Whereas with tables it would be
out = T(mask, {'excitation', 'fft'}) ;
Or
out = T(mask, [4,7]);
However, table are slower than structures.
  댓글 수: 2
Francesco Giuseppe Fornari
Francesco Giuseppe Fornari 2019년 12월 12일
Hi,
What's the meaning of this command you wrote? is mask a table variable?
Thanks
Walter Roberson
Walter Roberson 2019년 12월 12일
mask here is either a logical vector or a vector of indices, that you have constructed before this according to which entries you wish to select. For example,
now = datetime('now');
dates = [S.date];
mask = dates >= now - days(31);
out = struct('excitation', S(mask).excitation, 'fft', S(mask).fft);
or for tables,
now = datetime('now');
mask = T.dates >= now - days(31);
out = T(mask, {'excitation', 'fft'});

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by