Create pie chart in if loop

4 visualizaciones (últimos 30 días)
Nora Lindell
Nora Lindell el 9 de Ag. de 2019
Editada: Adam Danz el 12 de Ag. de 2019
Hello,
I´ve written the following loop
hold on
for i=2:1:48
x=File.data(8,i);
if x>10
pie(x)
end
end
My intention is to create a pie chart of the values in row 8 and columns 2-48 whith the condition thet the value in that cell is larger than 10 but i cant get it to work. Does anyone know what im doing wrong?
Thanks

Respuestas (2)

Adam Danz
Adam Danz el 9 de Ag. de 2019
Editada: Adam Danz el 12 de Ag. de 2019
From the documentation, "pie(X) draws a pie chart using the data in X. Each slice of the pie chart represents an element in X."
You need to provide all of the "slices" within the same input rather than one-by-one within a loop.
data = File.data(8,2:48); % <--- a vector of all slices
pie(data(data>10)) % <--- only provide slices >10
In your loop, the pie chart is being overwritten upon each iteration and only shows 1 "slice" at a time.

Star Strider
Star Strider el 9 de Ag. de 2019
I am not certain what you want, however the loop is likely not necessary.
Try this:
x = File.data(8, 2:48);
figure
pie(x(x>10))
axis equal

Categorías

Más información sobre Pie Charts en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by