How to relate two data columns in a data table.
2 views (last 30 days)
Show older comments
I have a data table that expresses how many times a certain thing happens.
eg,
0 appears 3 times
1 appears 4 times etc.
The time these numbers appear is related to another column and lasts for a certain amount of time. I was wondering if there is a way I can relate these 2 columns so I can get an output of something similar to this:
0 appears 3 times for 4 seconds
1 appears 4 times for 10 seconds.
The code I am currently using is
[u, ~, uidx] = unique(A(:));
counts = accumarray(uidx, 1);
fprintf('%d appears %d times\n', [u, counts].');
Thanks.
0 Comments
Answers (1)
Rajani Mishra
on 13 Feb 2020
I am not sure about the structure of the data table, but for finding the amount of time a certain thing lasts (considering that value is present in a column of the table) you can try using find() function on the column passing the respective thing as an input arguement.
Please find more information about find() in the below link :
4 Comments
Rajani Mishra
on 18 Feb 2020
From what I have understood is that you trying to calculate the duration every mode lasts from the GPS time of mode occurences. The minimum GPS time for a mode is considered the starting point for time calculation and maximum is the ending point.
From my understanding I have written below code taking 18 as mode for example, you can try below code for every mode.
Note : I have renamed your 'Example Results.xlsx' as 'ExampleResults.xlsx'
T = readtable('ExampleResults.xlsx');
time = T{:,1};
% time has the GPS time of all modes
mode = T{:,2};
% mode has all the mode values
% For a specific mode I have tried below script to get the duration it lasts for
indices = find(mode == 32);
% Find all the indices the mode occures
modeTimes = time(indices);
% Get all the GPS times
dur = max(modeTimes) - min(modeTimes);
% dur will have the time duration a mode lasts for
See Also
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!