Create empty dataset and populate it row by row

Hi,
I'm trying to create an object of the class dataset (Stats toolbox) with a few named "columns". I want such object to initially have no rows. Then, I would like to add new rows one by one. I've tried the code below to create the dataset but I get an error. Can anyone help me with this?
Thanks in advance
P.S. I could not submit this question to the "answers" section of the Mathworks website
% Column names are 'F1' and 'F2'
myDS = dataset([],'VarNames',{'F1','F2'})
??? Error using ==> setvarnames at 23
NEWNAMES must have one name for each variable in A.
Error in ==> dataset.dataset>dataset.dataset at 383
a = setvarnames(a,varnames); % names will be modified to make them valid

 채택된 답변

Mark
Mark 2011년 10월 24일

0 개 추천

Fangjun Jiang 23 minutes ago
VarNames={'F1','F2'}; myDS=dataset([],[],'VarNames',VarNames)

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 10월 24일

0 개 추천

myDS =dataset({[],'F1'},{[],'F2'});
Or to see it, myDS =dataset({1,'F1'},{2,'F2'})

댓글 수: 3

Mark
Mark 2011년 10월 24일
Thank you, but I want to avoid putting each variable name individually. I thought that the 'VarNames' was supposed to do that. I want a dataset with two columns, one is numeric and the other contains strings. How do I do that with the 'VarNames' option?
VarNames={'F1','F2'};
myDS=dataset([],[],'VarNames',VarNames)
Mark
Mark 2011년 10월 24일
That worked, thanks

댓글을 달려면 로그인하십시오.

태그

질문:

2011년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by