Effacer les filtres
Effacer les filtres

Referencing String in an array?

4 vues (au cours des 30 derniers jours)
Bolin
Bolin le 29 Sep 2013
Commenté : Azzi Abdelmalek le 29 Sep 2013
Hi guys, I am currently having the following problem
I want to create an array say:
A = ['Apple', 'Oranges']
And I want to access the array by the index of the items:
A(1) = Apple
A(2) = Oranges
But current, A(1) is only giving me a, A(2) is giving me p, so on
How do I access these items by their indices?
  1 commentaire
Azzi Abdelmalek
Azzi Abdelmalek le 29 Sep 2013
Bo commented
Thanks guys, been out of the matlab game for over a year and I can't remember anything! I even tried to use a struct but matlab struct is kind of crazy also.

Connectez-vous pour commenter.

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 29 Sep 2013
Use a cell array
A = {'Apple', 'Oranges'}
A{1}
A{2}
  1 commentaire
Azzi Abdelmalek
Azzi Abdelmalek le 29 Sep 2013
Modifié(e) : Azzi Abdelmalek le 29 Sep 2013
Bo, this is not struct it's a cell array. When you work with different type of data, you can not avoid cell array
doc cell

Connectez-vous pour commenter.


Wayne King
Wayne King le 29 Sep 2013
Modifié(e) : Wayne King le 29 Sep 2013
Why not use a cell array?
A = {'Apple', 'Oranges'};
Then
A{1}
and
A{2}
will give you what you want.

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by