Trying to plot graphs but Matlab stops responding and won't run the program

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)

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;

3 Comments

Okay. It's working now, sorry about that. I changed nothing, but it's mostly working. Only issue now is that it doesn't display the plots after I run the program once. I have to close and restart the program entirely for it to load the graphs. Not sure what that's about. Might just be my computer. Thank you for your help!
Matlab also isn't pulling up images either for some reason. Just tested that out now.
Okay, it's back to normal now. Sorry for wasting your time. Thank you very much regardless! I'll keep in mind your solution for future issues.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Asked:

on 15 Apr 2023

Commented:

on 16 Apr 2023

Community Treasure Hunt

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

Start Hunting!