plotting graph through while loop

1 回表示 (過去 30 日間)
Raqib Iqbal
Raqib Iqbal 2020 年 6 月 24 日
編集済み: KSSV 2020 年 6 月 24 日
n_device =10;
while(n_device<=50)
probability=binornd(n_device,.92)
n_device=n_device+10;
end
I want to plot a graph between n_device and probability for th 5 value of probability through this while loop,,please guide me ...

回答 (2 件)

KSSV
KSSV 2020 年 6 月 24 日
編集済み: KSSV 2020 年 6 月 24 日
x = zeros([],1) ;
y = zeros([],1) ;
n_device =10;
count = 0 ;
while(n_device<=50)
count = count+1 ;
probability=binornd(n_device,.92)
x(count) = n_device ;
y(count) = probability ;
n_device=n_device+10;
end
plot(x,y)
Use for loop:
n_device =10:10:50 ;
probability = zeros(size(n_device)) ;
count = 0 ;
for i = 1:length(n_device)
probability(i)=binornd(n_device(i),.92)
end
plot(n_device,probability)
  4 件のコメント
Raqib Iqbal
Raqib Iqbal 2020 年 6 月 24 日
x = zeros([],1) ;
y = zeros([],1) ;
n_device =10;
count = 0 ;
while(n_device<=50)
count = count+1 ;
probability=binornd(n_device,.92)
x(count) = n_device ;
y(count) = probability ;
n_device=n_device+10;
end
plot(x,y)
for this code -->>>>plot(probability./n_device,n_device),,,is not working sir after changing x & y.....for this code i want to draw 2nd graph which is (probability/n_device vs n_device)
KSSV
KSSV 2020 年 6 月 24 日
Hello here x is n_device, y is probability ..so you have to use
plot(y./x,x) ;

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


Ashish Azad
Ashish Azad 2020 年 6 月 24 日
Store the five values in vector, a vector containing values of n_device and a vector containing values of probability to the corresponding n_device
and use plot function: plot(<n_device_vector>,<probality>)
This should work
Alternatively you can also try plotting using plot function and writing hold on at starting of loop, let me know if this work.

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by