Code for simulating multiple matrices

조회 수: 1 (최근 30일)
Caillin O'Rourke
Caillin O'Rourke 2020년 3월 15일
댓글: Sriram Tadavarty 2020년 3월 17일
T = ones(5);
D = 0.9;
Deg = D*eye(5);
Mn = zeros(5);
N = [0 0 0 0 0;0 0 0.2 0 0;0 0.2 0 0.2 0;0 0 0.2 0 0;0 0 0 0 0];
M1 = (T - (Deg * (T-Mn) - (N*Mn)));
M2 = (T - (Deg * (T-M1) - (N*M1)));
Hello all,
Above are the 5x5 variables and rule im trying to simulate. Im relatively new to MatLab, and im wondering if theres any simple way of replacing the likes of M1 and M2, to give me all the ranges of simulated answers (Mn), to whatever range I want?
Thanks!

채택된 답변

Sriram Tadavarty
Sriram Tadavarty 2020년 3월 16일
Hi Caillin,
To get the output for all the ranges of simulated answers from M1 to Mn, you can use a for loop.
n = 5;
T = ones(n);
D = 0.9;
Deg = D*eye(n);
Mn = zeros(n);
N = randn(n); %[0 0 0 0 0;0 0 0.2 0 0;0 0.2 0 0.2 0;0 0 0.2 0 0;0 0 0 0 0];
for i = 1:n
M(:,:,i) = (T - (Deg * (T-Mn) - (N*Mn)));
Mn = M(:,:,i);
end
% All the values of M1...Mn is in the matrix M
disp(M);
Hope this helps.
Regards,
Sriram
  댓글 수: 2
Caillin O'Rourke
Caillin O'Rourke 2020년 3월 17일
Hi Sriram!
Yes thats perfect! Going from here, im trying to cap all the values to 1, meaning they wont go any higher than 1. Inside the for loop you have created, I tried creating a loop shown below but it isnt working. Any thought why?
for i =1:8
M(:,:,i) = (T - (Deg * (T-Mn) - (N*Mn)));
Mn = M(:,:,i);
for Mn (Mn>1)
Mn = 1
end
end
Sriram Tadavarty
Sriram Tadavarty 2020년 3월 17일
Hi Caillin,
The for syntax is not used properly. What do you want to do here? Inorder to make all the values of Mn higher than 1 to the value of 1, you can perform Mn(Mn>1) = 1; rather than using the for loop.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by