given data of date but same date repeated 20 times how to use unique to combine it all in matlab

You can combine duplicated rows of a matrix by using the unique function with the rows option. Here's an example:

main.m
% Example data
data = [2019, 5, 1, 10;
        2019, 5, 2, 11;
        2019, 5, 3, 12;
        2019, 5, 2, 8;
        2019, 5, 3, 9;
        2019, 5, 1, 13];

% Find unique rows and keep the first occurrence
unique_data = unique(data, 'rows');

% Result
% unique_data = 
%      2019     5     1    10
%      2019     5     2    11
%      2019     5     3    12
%      2019     5     2     8
%      2019     5     3     9
421 chars
19 lines

In this example, the rows with the same date appear twice or three times. We use unique to combine the duplicated rows while keeping the order of the original matrix. The resulting matrix unique_data has five rows instead of six.

related categories

gistlibby LogSnag