Make probability matrix from data set

1 次查看(过去 30 天)
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 个评论
Dylan Girodat
Dylan Girodat 2020-3-6
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
....

请先登录,再进行评论。

回答(1 个)

Koushik Vemula
Koushik Vemula 2020-3-9
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

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by