Convert vector of cells to variables
Afficher commentaires plus anciens
Hi! I'm importing data from excel and I'm finding the position of the data of interest using findstr and it works fine. My problem is that I want to get a string from the vector of cells (eg. Temperature) and assigning it a vector of digits. This is how I want it to be:
Text={'Temp', 'Humidity', 'Age'}
num=[20 0.8 2; 22 0.85 2.1; 23 0.9 2.2]
Temp=[20 22 23]
Thankful for help Regards Johan
Réponse acceptée
Plus de réponses (2)
Walter Roberson
le 17 Juin 2013
1 vote
That is not recommended; please see
Andrei Bobrov
le 17 Juin 2013
Modifié(e) : Andrei Bobrov
le 17 Juin 2013
use dataset array
Text={'Temp', 'Humidity', 'Age'}
num=[20 0.8 2; 22 0.85 2.1; 23 0.9 2.2]
d = mat2dataset(num,'VarNames',Text);
>> d.Temp
ans =
20
22
23
or
d2 = cell2struct(num2cell(num,1),Text,2);
d2.Temp
ans =
20
22
23
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!