Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Headers in dataset (Matlab)
- dmsdb = dataset({ 'John','Name'},{'Amsterdam','City'},{10,'number' });
- produces:
- Name City number
- John Amsterdam 10 --> Headers are good!
- dmsdb(1,1:3) = dataset({ cellstr('John'),'Name'},{cellstr('Amsterdam'),'City'},{10,'number' });
- Produces:
- Var1 Var2 Var3
- 'John' 'Amsterdam' 10
- data = dataset({[], 'Name'}, {[], 'City'}, {[], 'number'});
- data = dataset([], [], [], 'VarNames', {'Name', 'City', 'number'});
- >> data
- data =
- [empty 0-by-3 dataset]
- >> get(data, 'VarNames')
- ans =
- 'Name' 'City' 'number'
- >> data = [data; dataset({'John'}, {'Amsterdam'}, 10, 'VarNames', get(data, 'VarNames'))]
- data =
- Name City number
- 'John' 'Amsterdam' 10
- >> dmsdb = dataset({ {'John'},'Name'},{{'Amsterdam'},'City'},{10,'number' });
- dmsdb =
- Name City number
- 'John' 'Amsterdam' 10
- %# create dataset with no rows
- ds = dataset(cell(0,1),cell(0,1),zeros(0,1));
- ds.Properties.VarNames = {'Name', 'City', 'number'};
- %# adding one row at a time
- for i=1:3
- row = {{'John'}, {'Amsterdam'}, 10}; %# construct new row each iteration
- ds(i,:) = dataset(row{:});
- end
- %# adding a batch of rows all at once
- rows = {{'Bob';'Alice'}, {'Paris';'Boston'}, [20;30]};
- ds(4:5,:) = dataset(rows{:});
- >> ds
- ds =
- Name City number
- 'John' 'Amsterdam' 10
- 'John' 'Amsterdam' 10
- 'John' 'Amsterdam' 10
- 'Bob' 'Paris' 20
- 'Alice' 'Boston' 30
- vars = {'Name', 'City', 'number'};
- ds = [ds ; dataset(rows{:}, 'VarNames',vars)]
- % 1) Create the 3 variables of interest, then make the dataset.
- % Make sure they are column vectors!
- >> Name = {'John' 'Joe'}'; City = {'Amsterdam' 'NYC'}'; number = [10 1]';
- >> dataset(Name, City, number)
- ans =
- Name City number
- 'John' 'Amsterdam' 10
- 'Joe' 'NYC' 1
- % 2) More compact than doing 3 separate cell arrays
- >> dataset({{'John' 'Amsterdam' 10} 'Name' 'City' 'number'})
- ans =
- Name City number
- 'John' 'Amsterdam' [10]
Add Comment
Please, Sign In to add comment