Difference and probability in plot

1 回表示 (過去 30 日間)
Brave A
Brave A 2019 年 9 月 3 日
コメント済み: Brave A 2019 年 9 月 4 日
Hello I tried to plot this but it's show me "Vectors must be the same length.
Error in (line 17)
plot(difference,probability,'b--'"
would you please help me to fix the problem?
thanks in advance.
difference=[];
probability=[];
for diff=-5:1:5
sum=0;
for g=1:6
for r=1:6
if(g-r==diff)
sum=sum+(1/36);
end
end
end
differnce=[difference diff];
probability=[probability sum];
end
figure
plot(difference,probability,'b--')
xlabel('D');
ylabel('P');
axis([-5 5 0 .2]);

採用された回答

KSSV
KSSV 2019 年 9 月 3 日
編集済み: KSSV 2019 年 9 月 3 日
thedifference=-5:1:5 ;
N = length(thedifference) ;
probability=zeros(N,1) ;
for i = 1:N
thediff = thedifference(i) ;
thesum=0;
for g=1:6
for r=1:6
if(g-r==thediff)
thesum=thesum+(1/36);
end
end
end
probability(i) = thesum;
end
figure
plot(thedifference,probability,'b--')
xlabel('D');
ylabel('P');
axis([-5 5 0 .2]);
  5 件のコメント
KSSV
KSSV 2019 年 9 月 3 日
Give your desired values in the line:
thedifference=-5:1:5 ;
Brave A
Brave A 2019 年 9 月 4 日

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by