Need assistance updating a Matrix While code is iterating
Show older comments
The Idea behind my code is to take an empty matrix and, based on a series of subroutines, refill it with new values. The issue I'm having is that rather than storing the new values in the matrix and testing this new matrix the code is erasing and overwriting any previous alterations to the matrix. When the code does loop it hits its recursion limit when the goal is to simply fill the empty spaces in the M(x) matrix.
n=5; %matrix size
M=zeros(n);%matrix of all zeros that is being updated
I=1; %number of iterations
C=zeros(size(M));%matrix of random numbers that determine the directional value assigned to each position
D=zeros(size(M));%matrix of positional values
for y=randi(n),x=randi(n);
if M(x,y)==0
C(x,y)=NumberGenerator; %determines what random value is assigned to the matrix postion
if C(x,y)<.2
M(x,y)=0;
D(x,y)=0;
Test; %Name of this code, meant to loop this process
elseif C(x,y)>.2
M(x,y)=1;
MatrixGenV2; %subroutine that generates a directional value at each position based on C(x,y)
BoundaryCondition; %Boundary condition I've placed on the matrix
Test;
end
elseif M(x,y)>0
Test;
end
end
Keep in mind I'm very new to Matlab so if my code isn't as streamlined as it can be that's why. Thank you in advance for any help.
2 Comments
madhan ravi
on 28 Nov 2018
NumberGenerator , MatrixGenV2 , BoundaryCondition , Test??
William Diaz
on 28 Nov 2018
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices 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!