Set a variable in a Matlab Dataset array for a single value

Let's say I have an array of a data set (from a statistics toolbox):

>> myds
myds = 
    Observation    SheepCount
    1              88        
    2               2        
    3              14        
    4              12        
    5              40

I collect data from different sources, so I would like to set "Location" to 4 in all these observations, before I vertcatset this data set together with others. In a regular matrix, you say myds(:, 3) = 4that will translate 4 to all spaces in the matrix.

Is there a way to do this in a dataset without using repmat?

Things I tried that don't work:

myds(:, 'Location') = 4
myds(:).Location = 4
myds.Location(:) = 4
myds.Location = 4

Things that work:

myds.Location = 4; myds.Location(:) = 4; % have to run both
myds.Location = repmat(4, length(myds), 1);

So, do I need to overcome my disgust for repmat? Thank you. The strike>

edit . I assume that I really want to avoid specifying the sizes of the array of 4.

+3
2

ones repmat.

myds.Location=4*ones(1,5);
+2

, :

myds.Location= myds.Observation*0 + 4;
+1

All Articles