Trying to plot graphs but Matlab stops responding and won't run the program
Show older comments
When I try to run the following code, MatLab won't run the program and stops responding, forcing me to quit and return again. When I hit run, Matlab gives me the blue spinning wheel and stops functioning.
For context, I'm running Matlab through my university's program. So Matlab is run through an application. I've never had any issues running programs with complex images or anything like that. Any feedback is appreciated.
%Create 3 plots for number of movies in every type, number of tickets sold
%per type, and average number of tickets sold per type
clc; clear;
movieType = 1:1:11;
numMovies = [273 106 223 134 110 89 39 55 23 41 10];
numTickets = [371176470 323532944 94998758 11765530 176581251 98962594 525514 45842523 26458555 67312441 3667257];
averageTickets = [0 0 0 0 0 0 0 0 0 0 0];
for x = 1:1:11
averageTickets(x) = numTickets(x)/numMovies(x);
end
subplot(1,3,1)
plot(movieType, numMovies, 'b--');
subplot(1,3,2)
plot(movieType, numTickets, 'b--');
subplot(1,3,3)
plot(movieType, averageTickets, 'b--');
Answers (1)
Image Analyst
on 16 Apr 2023
Where does it stop? Have you tried stepping through it a line at a time?
It ran for me.
Try putting
fprintf('x = %d', x);
inside the for loop and see where it stops. And put a fprintf after the loop and put drawnow after the calls to plot.
for x = 1:1:11
fprintf('x = %d\n', x);
averageTickets(x) = numTickets(x)/numMovies(x);
end
fprintf('Done with for loop.\n');
subplot(1,3,1)
plot(movieType, numMovies, 'b--');
drawnow;
subplot(1,3,2)
plot(movieType, numTickets, 'b--');
drawnow;
subplot(1,3,3)
plot(movieType, averageTickets, 'b--');
drawnow;
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!