How to relate two data columns in a data table.

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.

답변 (1개)

Rajani Mishra
Rajani Mishra 2020년 2월 13일

0 개 추천

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

I have attached a copy of the results. I do not think the find() function will work as they time is not present in the column only the GPS time.
can you provide your data table? because from the excel sheet's GPS time I am not able to understand whether its the time that certain thing appeared or something else, also can you explain more about your question
I am not sure how to attach the data table but I have changed the data I am going to use. Basically each count occurs at a certain time and I am looking to get a script which will tel me:
a) how many times each mode occurs i.e, 18 occurs 5 times
b) how long this occurance lasts, i.e 18 occurs 5 times for 5 seconds
I have a script which tells me how many times each mode occurs so I am just looking for an example to relate the two data columns so I can get b) to happpen as well.
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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Time Series Events에 대해 자세히 알아보기

질문:

2020년 2월 10일

댓글:

2020년 2월 18일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by