|
As with any MATLAB array, performance is usually best if you can
"preallocate". In this case, you might do something like
VarNames = {'F1','F2'};
myDS = dataset(zeros(n,1),zeros(n,1),'VarNames',VarNames)
...
myDS.F1(i) = ...
myDS.F2(i) = ...
It's not _required_, but you may find that things work much faster if
you know in advance how many rows you'll need.
On 10/24/2011 6:28 PM, Mark wrote:
> Thanks to Fangjun Jiang, who kindly provided the answer to my question
> about creating an empty dataset:
>
> VarNames={'F1','F2'};
> myDS=dataset([],[],'VarNames',VarNames)
>
> I am posting it here so that people who search USENET groups can find
> this solution
>
>
>
> "Mark" wrote in message <j83u8i$i9c$1@newscl01ah.mathworks.com>...
>> 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
|