MATLAB Answers

Steven
0

Help on creating an cell array

Asked by Steven
on 28 Jul 2013

I am trying to create an cell array that will show names and ages of each person. I do not know how to begin with structuring this.

  0 Comments

Tags

Products

No products are associated with this question.

1 Answer

Answer by Azzi Abdelmalek
on 28 Jul 2013
Edited by Azzi Abdelmalek
on 28 Jul 2013
 Accepted answer

   A={'Name' 'Age';'Mick'  70;'Jhon' 80}

%or

header={'name' 'age'}
names={'Mick';'Jhon';'Ana'}
ages={70;80;20}
Yourcell=[header;[names ages]]

% Or you can also use a struct array

v=struct('name',{'Mick','Jhon','Ana'},'Age',{70 80 20})
% If you want to access to each element:
%first person 
v(1).name
v(1).Age
%second person
v(2).name
v(2).Age

  1 Comment

Steven
on 28 Jul 2013

Thank you very much! Those examples were very helpful.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!