MATLAB: How to input excluded data

excluded datainputting dataMATLABmissing data

So I have recorded behaviours 'Tier_Labels' (e.g. walking, running, sitting) for individual birds (identified by Bird, Pen & Strain). I have aggregated the data to develop a cumulative sum each specific Tier_Label was performed at different habituation times.
%% Aggregation SPSS Function in Matlab
% Creates a table of SUM Total_Duration2 for each Tier Label
G4 = groupsummary(T,{'Bird','Pen','Strain','Habituation','Tier_Labels',},'sum', 'Total_Duration2')
However, some of these behaviours, don't occur for every bird, at every habituation time. I was to create code (potentially a loop) which will say:
For every individual (Bird,Pen,Strain,Habituation),
If 'Behaviours' are missing from the recorded 'Tier_Labels'
Add in a row with that behaviour listed as Total_Duration 0.00
I think a loop is the right way forward but I'm a novice at coding and I'm not sure if there is function that can look at a variable and identify missing labels from a pre-written varibale and then input these into the data set.
Hopefully that makes sense, can anyone help? Or give me some pointers in the right direction?
Thanks 🙂

Best Answer

  • Try this
    A = importdata('data.txt','\t');
    T = A.textdata;
    blist = unique(T(:,end)); % create full list of unique behaviours
    k = 1;
    for i = 1:size(T,1)
    if ~all( strcmp(T(i,1:4),T(i+1,1:4)) ) % if rows are not similar
    clist = setdiff(blist,T(k:i,5)); % list of lack behaviours
    T1 = repmat(T(i,1:4),[length(clist) 1]);% duplicate rows Bird Pen Strain Habituation
    T = [T; T1 clist]; % add lack of behaviours
    k = i+1;
    data1 =;
    data = zeros(size(T,1),2); % zero numerical list (count duration)
    data(1:size(data1,1),:) = data1; % fill first values (rest are zeros)
    R = [cell2table(T) table(data)]; % create full table