MATLAB: Can I update a pie chart data in real time using XData and YData in MATLAB 7.12 (R2011a)

MATLAB

How can I update a pie chart in real time, similar to using 'XData' and 'YData' to update a plot in real time?

Best Answer

PIE does not produce a single handle for the entire plot; instead, it produces a collection of PATCH graphics to represent the slices, and a series of text labels. Updating the PIE would involve first, normalizing the data vector then creating cartesian coordinates from the polar representation of the data vector. Therefore, the most direct way to work around this issue is to call the PIE function repeatedly using the new data while maintaining the same axes.
This segment of code walks through the resulting workaround.
clc, clear all, close all;
a = rand(25,1); % original data vector "a"
pie(a);
hold on; % plot subsequent data on same axes
b = rand(25,1); % new data vector "b"
clf('reset') % clear current figure axes
pie(b) % redraw PIE with new data vector b
drawnow; % draw immediately and clear handle queue
hold off; % henceforth, create new axes