I have a plot and i want to switch it to histogram ,how i can do it?

조회 수: 1 (최근 30일)
tasneem haikal
tasneem haikal 2020년 4월 16일
댓글: Rena Berman 2020년 5월 14일
clear all
numsteps=1000;
numwalks=1000;
stepmatrix = sign(rand(numwalks,numsteps)-0.5*ones(numwalks,numsteps));
posmatrix = (cumsum(stepmatrix,2))
mat=zeros(numwalks,1);
for j = 1:numwalks;
last = find(posmatrix(j,:)==0,1,'last');
if isempty(last)==0;
mat(j)=last;
end
end
mat
edges=-0.5:1:(numsteps+0.5)
[N,edges]=histcounts(mat,edges)
probability=N*(1/numwalks)
figure;
h1=plot(1:numsteps , probability(2:end));
figure
i write this code , and then i get what a plot like i want , but i want to plot it like a histogram
what should i add?
i try to add histogram(1:numsteps , probability(2:end)) but then i get an empty plot

답변 (2개)

Walter Roberson
Walter Roberson 2020년 4월 16일
bar(mean([edges(1:end-1);edges(2:end)]),N)
This uses the center of the bin as the bar position.

Sean de Wolski
Sean de Wolski 2020년 4월 16일
Something like this
histogram(mat,edges,'Normalization','probability');
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 4월 16일
Yes, the original histogram is too fine grained to be useful.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by