フィルターのクリア

Make probability matrix from data set

1 回表示 (過去 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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by