Make probability matrix from data set

I have a data set that consists of time and multiple distances, it is formated as:
Time Distance 1 Distance 2 Distance 3 ...
0 2 1 2
1 3 3 4
2 4 4 5
3 5 6 4
4 7 6 4
I would like to transform the information into a probability matrix to make a heat plot. On the graph I would like the X axis to be the time column, the Y axis to be distances, and the Z-axis to be the probability of each distance occuring at the respective time.
Any help would be much appreciated,
Thank you,
Dylan

1 Comment

Sorry I should say the output that would work for me would be:
Time Distance Probability
0 1 X
0 2 X
0 3 X
0 4 X
0 5 X
0 6 X
0 7 X
1 1 X
1 2 X
1 3 X
1 4 X
1 5 X
1 6 X
1 7 X
2 1 X
....

Sign in to comment.

Answers (1)

According to my understanding, you’d like to have a matrix (say ‘Prob’) which stores the data values in an n-by-3 matrix where first column contains time, second column contains distance value and third column contains the probability of distance.
You can do it in the following manner.
data=[[2,1,2];[3,3,4];[4,4,5];[5,6,4];[7,6,4]]; %Example Dataset
[m,n]=size(data);
k=1;
[0,1,sum(data(1,:)==1)/length(data(1,:))];
for i = 1:m
x=unique(data(i,:)','rows');
for j = 1:length(x)
Prob(k,:)=[i-1,x(j),sum(data(i,:) == x(j))/(length(data(i,:)))];
k=k+1;
end
end
As you can see the desired output is stored in the variable ‘Prob’. Here ‘data’ represents the data set that consists of time and multiple distances where time is ‘index-1’ and values will be your distances

Asked:

on 6 Mar 2020

Answered:

on 9 Mar 2020

Community Treasure Hunt

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

Start Hunting!