Alternate to the circshift function in a 3d matix for an agent based model
Show older comments
Hey there,
I have a 3 dimensional matrix randworld and need to perform certain calculations on each the row and column cell around a randomly selected cell holding the third dimension constant. I used the circshift function for this. However as I need to do 121000000 iterations, this method is very slow. I noticed the circshift function consumes most of the time (from profile viewer). Could you please suggest an alternative to the circshift function.
I have copied the code below so that you have an idea of what I'm looking to do.
Thank you.
nside=11; %rows and coloumns
u=120; %neighbours
randworld=randi(10,nside,nside,5); %create a random 3-d world
%select a random agent and feature
randomagentr=randi(10,1);
randomagentc=randi(10,1);
randomfeat=randi(5,1);
nsize=0;
%neighbourhood
for q=-5:5
for w=-5:5
if abs(q)+abs(w)~=0
nsize=nsize+1;
neigh(nsize,:)=[q,w];
end
end
end
for k=1:u
vm=circshift(randworld,[neigh(k,1),neigh(k,2)]);
v=vm(randomagentr,randomagentc,randomfeat);
%perform certain computations on this new variable v
end
Accepted Answer
More Answers (0)
Categories
Find more on Electromagnetics 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!