Filter löschen
Filter löschen

Make probability matrix from data set

1 Ansicht (letzte 30 Tage)
Dylan Girodat
Dylan Girodat am 6 Mär. 2020
Beantwortet: Koushik Vemula am 9 Mär. 2020
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 Kommentar
Dylan Girodat
Dylan Girodat am 6 Mär. 2020
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
....

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Koushik Vemula
Koushik Vemula am 9 Mär. 2020
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

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by