Conditional in for-loop

3 Ansichten (letzte 30 Tage)
noname
noname am 8 Feb. 2021
Kommentiert: Bob Thompson am 8 Feb. 2021
x = 0:0.1:10;
y = exppdf(x,2);
Plot the pdf.
figure;
plot(x,y)
what if I have P (0 <x< 10) , how should I write it in matlab?
Thanks
  3 Kommentare
noname
noname am 8 Feb. 2021
P is probability where x > 0 and x<10
Bob Thompson
Bob Thompson am 8 Feb. 2021
Ah, probability isn't really my strong suit, as a concept.
From what little I do understand, wouldn't the probability of any individual value of x (not sure if this is what condition you're actually looking at) is within the range of 0 < x < 10 just be the percentage of x values within that range? If so, you can calculate that like the following:
P = sum(x>0&x<10)/length(x);

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Lighting, Transparency, and Shading 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