How does one create a dataset from a large array and subsequently name the variables?
Mostra commenti meno recenti
I have a body data array read from a excel file: 9000-by-130. I also have the header line read from the same file: 1-by-130. I am trying to create a 900-by-130 dataset from the data array while using the elements of the header line array as variable names.
data = <9000x130 dataset>
headers = <1x130 cell>
The issue I'm having is...
D = dataset(array(:));
...just creates a 9000-by-1 dateset!? So, for example,
for i = 1:size(headers,2)
dataSet.Properties.VarNames{i} = headers{i};
end
...cannot find variables to match elements in headers{i}.
The only solution is to enter the variables and the names manually 130 times!
dataSet = dataset(data(:,1),data(:,2)...data(:,130),'VarNames',{'Var1','Var2',...,'KillMeNow'});
Surely there's a simpler way. Is there?
Risposta accettata
Più risposte (2)
Wayne King
il 18 Set 2012
Why don't you organize the excel file and then create the dataset directly from the excel file with the
A = dataset('XLSFile',filename,...
syntax?
1 Commento
Tolulope
il 18 Set 2012
Javier
il 18 Set 2012
0 voti
Hello Tolulope
This is what you have to do. In this case, data has 5 columns.
Step 1 (define the names)
for i=1:size(data,2)
VarNames{1,i}=['Var ',num2str(i)];
end
Step 2 (introduce in the data set)
dataSet = dataset(data(:,1),data(:,2),data(:,3),data(:,4),data(:,5),'VarNames',VarNames);
If this solve your question please grade or post a comment.
Best regards
Javier
1 Commento
Tolulope
il 18 Set 2012
Categorie
Scopri di più su Environment and Settings in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!