Using While Loop For Grouping Pie chart "Slices"

Hello I am writing a script for a pie chart for reaction timings from a game. I want the pie chart to depict the occurrances of different reaction speeds. I have an array 'x' with all the speeds and I wanted to catagorize them using a "while loop" and plotting these grouped variables as a pie chart. But I am having errors can someone please help me.
x= [0.66,0.38,0.01,0.01,0.13,0.01,1.38,3.96,1.04,0.01,0.39,0.38,0.36,0.32,2.61,2.73,0.01,0.95,1.94,0.01,0.01,1.18,1.42,0.01,0.37,0.45,0.01,3.31,0.77,0.04,1.45,1.38,1.00,0.03,3.05];
int n = 1;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int f = 0;
while (n<x) {
if(x==.01){
a++;
}
if(.01<=x<=.25){
b++;
}
if(.25<=x<=.75){
c++;
}
if(.75<=x<=1.0){
d++;
}
if(x>1){
f++;
}
n++;
}
h=[a,b,c,d,f];
pie(h);

 Akzeptierte Antwort

VBBV
VBBV am 6 Dez. 2022
x= [0.66,0.38,0.01,0.01,0.13,0.01,1.38,3.96,1.04,0.01,0.39,0.38,0.36,0.32,2.61,2.73,0.01,0.95,1.94,0.01,0.01,1.18,1.42,0.01,0.37,0.45,0.01,3.31,0.77,0.04,1.45,1.38,1.00,0.03,3.05];
n = 1;
a = 0;
b = 0;
c = 0;
d = 0;
f = 0;
i = 1;
while i<numel(x)
if x(i)==.01
a = a+1;
elseif x(i)>=.01 & x(i)<=.25
b = b+1;
elseif x(i)>=.25 & x(i)<=.75
c=c+1;
elseif x(i)>=.75 & x(i)<=1.0
d=d+1;
elseif x(i)>1
f=f+1;
n=n+1;
end
i = i+1;
h=[a,b,c,d,f];
end
pie(h);

1 Kommentar

Thank you respected sir or madam. This was very useful for me!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by