Matlab Gui plot doesn't animate using drawnow.

23 views (last 30 days)
I am new in GUI. I have a GUI with a single axes that loads a .mat file. from The .mat file, I convert a 18000*132 matrix called "MelisaW". Then I tried to plot few of the sequences of rows of that matrix with scatter3. The code is as below:
function open_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to open (see VARARGIN)
% Choose default command line output for open
handles.output = hObject;
load('PMelisa01.mat', 'PMelisaD20180404Walkingnone01');
MelisaW = cell2mat(PMelisaD20180404Walkingnone01):
ax1 = handles.axes1;
for i=1:200
PMelisaD20180404Head_x= MelisaW(i,4)/100;
PMelisaD20180404Head_y= MelisaW(i,5)/100;
PMelisaD20180404Head_z= MelisaW(i,6)/100;
%2....
scatter3(ax1,PMelisaD20180404Head_x,PMelisaD20180404Head_y,PMelisaD20180404Head_z,'filled')
%2 scatter3(..)...
drawnow
end
% Update handles structure
guidata(hObject, handles);
function varargout = open_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
I Used the "drawnow" command to animate the scatter plots but instead of plotting for 200 times it only shows 200th plot. I have used the same code as normal .m file and it animated. It is not working only on GUI. Any help to solve the problem is highly appreciated.

Answers (1)

Walter Roberson
Walter Roberson on 13 Apr 2018
You do not appear to have a "hold on", and you are scatter3() only a single point at a time. MATLAB is going to create the one point, yes, but it is going to automatically create xlim and ylim according to the data, and would mostly end up centering the point on the display. The result would be a point staying mostly in the same screen location while the axes changes to reflect the position.
If you had a hold on in effect, then it would be adding to the displayed points instead.
You should also be considering switching to animatedline for this purpose instead of doing a scatter3() each time.

Categories

Find more on Animation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!