Sudden slowness of MATLAB - same code, same PC

1 view (last 30 days)
Woody247
Woody247 on 16 Mar 2015
Commented: dpb on 17 Mar 2015
I have had an issue where this code now runs slowly, when it was running quickly before.
The code is:
% function [Score] = Location(g,Theatre,steps,GTotal,PopNum,ThNum)
% Code to plot where max the robot is moving through a number of steps in
% each a strategy for each of the theatres produced, a total score is then
% outputted.
tic
% Last edited: 04/03/2015 by Pete Woodward
clear all; close all
g = 1;
PopNum = 200; % # of genes in population, KEEP EVEN
ThNum = 100; % number of theatres to generate
GenNum = 100;
steps = 200;
load('Theatre0_100_10x_10y.mat')
load('GT200.mat')
GTotal(1,:,:) = GT1;
Score = zeros([PopNum ThNum]); %initialise score array
% for each gene in the population
for s = 1:PopNum,
% for each theatre
for t = 1:ThNum,
% establish a dynamic theatre that can be modified and disguarded
DynThea = Theatre(t,:,:);
% change initialise location (1,1) in theatre, (2,2) with walls
Loc = [2 2];
% execute for 200 steps of each strategy (GTotal)
for j = 1:steps,
% get next step for locale - check theatre values to get a base
% 3 value for locale, convert to base 10 for index within
% GTotal(:,:,ind)
% Gene consists of [N S E W C]
% N = DynThea(Loc(1),Loc(2)-1)*81; % North Locale
% S = DynThea(Loc(1),Loc(2)+1)*27; % South Locale
% E = DynThea(Loc(1)+1,Loc(2))*9; % East Locale
% W = DynThea(Loc(1)-1,Loc(2))*3; % West Locale
% C = DynThea(Loc(1),Loc(2))*1; % Current Locale
% LocaleB10 = N+S+E+W+C+1; % Base 10 decimal Locale
% combining above lines into one line speeds up each call of
% Location.m by around 4 seconds (from 11 seconds)
step = GTotal(g,s,((DynThea(1,Loc(1),Loc(2)-1)*81)+...
(DynThea(1,Loc(1),Loc(2)+1)*27)+...
(DynThea(1,Loc(1)+1,Loc(2))*9)+...
(DynThea(1,Loc(1)-1,Loc(2))*3)+...
(DynThea(1,Loc(1),Loc(2))*1)+1));
% check for random first, change step if random occurs
if step == 6
% change to appropriate random direction or pick up rubbish
step = floor(5*rand)+1;
end
% check for other values or random direction
if step == 1
Loc(2) = Loc(2) - 1; %North
% check for walls
if DynThea(1,Loc(1),Loc(2)) == 2
Score(s,t) = Score(s,t) - 5; % hit a wall
Loc(2) = Loc(2) + 1;
end
elseif step == 2
Loc(2) = Loc(2) + 1; % South
% check for walls
if DynThea(1,Loc(1),Loc(2)) == 2
Score(s,t) = Score(s,t) - 5; % hit a wall
% check if it is the first movement
Loc(2) = Loc(2) - 1;
end
elseif step == 3
Loc(1) = Loc(1) + 1; %East
% check for walls
if DynThea(1,Loc(1),Loc(2)) == 2
Score(s,t) = Score(s,t) - 5; %hit a wall
% check if it is the first movement
Loc(1) = Loc(1) - 1;
end
elseif step == 4
Loc(1) = Loc(1) - 1; % West
% check for walls
if DynThea(1,Loc(1),Loc(2)) == 2
Score(s,t) = Score(s,t) - 5; % hit a wall
% check if it is the first movement
Loc(1) = Loc(1) + 1;
end
elseif step == 5
if DynThea(1,Loc(1),Loc(2)) == 0
% no rubbish so -1 points
Score(s,t) = Score(s,t) - 1;
else
% must be rubbish there
Score(s,t) = Score(s,t) + 10;
DynThea(1,Loc(1),Loc(2)) = 0; % remove the rubbish
end
end
end
end
end
toc
This ran on my PC at around 0.5 seconds using tic toc. Until I cancelled another program using Neural Networks Toolbox (using ctrl + C)
After which my code now takes 14.8 seconds using Tic Toc.
I have tried reinstalling MATLAB 2014b but this hasn't worked. I am on a trial for that but it also runs slow in my student copy of 2014a.
PC Specs in dxdiag.txt attached.
The code runs fine on the university computers so it isn't a code issue.
Any suggestions appreciated.
  7 Comments
Woody247
Woody247 on 16 Mar 2015
James - I'll get some comparisons later tonight or tomorrow when I'm next on campus.
Dpb - I have just done a fresh install, everything is default but I presume up to date. The uni PC is running 2014a not 2014b, however my home version of 2014a also has the same issue.
I am running Avast antivirus but nothing is clogging up CPU or memory on my machine.
dpb
dpb on 17 Mar 2015
"...nothing is clogging up CPU or memory on my machine."
Something must be or symptoms wouldn't be as described.
Perhaps you're not actually comparing what you think you are? Possibly a data-specific issue or a modified version of the m-file owing to some edit/change, etc., ...???

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with MATLAB 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!