Make probability matrix from data set

조회 수: 3 (최근 30일)
Dylan Girodat
Dylan Girodat 2020년 3월 6일
답변: Koushik Vemula 2020년 3월 9일
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에서 Smoothing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by