Azzera filtri
Azzera filtri

Help on creating structures??

1 visualizzazione (ultimi 30 giorni)
Mary
Mary il 28 Feb 2014
Risposto: Jacob Halbrooks il 28 Feb 2014
The only way I know how to create a structure where all of my sections are ordered is like so:
struct1(1).name='Krista';
struct1(2).name='Kranthi';
struct1(3).name='Kevin';
struct1(4).name='Kalil';
struct1(5).name='Kristen';
struct1(1).date=[10 5 1993];
struct1(2).date=[6 16 1990];
struct1(3).date=[4 20 1991];
struct1(4).date=[7 10 1819];
struct1(5).date=[2 31 1992];
Is there are more concise way to write the code for this and still get the same result?? Help appreciated :) thank you!

Risposta accettata

Jacob Halbrooks
Jacob Halbrooks il 28 Feb 2014
You could enter your data into a two-column cell array and then use CELL2STRUCT:
data = {'Krista', [10 5 1993]; ...
'Kranthi', [6 16 1990]; ...
'Kevin', [4 20 1991]; ...
'Kalil', [7 10 1819]; ...
'Kristen', [2 31 1992]};
s = cell2struct(data, {'name', 'date'},2)

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by