필터 지우기
필터 지우기

How to do this

조회 수: 2 (최근 30일)
Hunter Herrenkohl
Hunter Herrenkohl 2018년 6월 18일
답변: Jan 2018년 6월 18일
I have
R = input('Please enter a number of rows for the matrix');
C = input('Please enter a number of columns for the matrix');
M = randi(2, R, C);
M(M>1)=-1;
M3 = M
M4=NaN(R+2,C+2)
M4(2:end-1,2:end-1)=M3
c=zeros(R,C)
for i = 2:R+1
for j=2:C+1
arr = [M4(i-1,j) M4(i+1,j) M4(i,j+1) M4(i,j-1)]
c(i-1,j-1)=nnz(ismember(arr,M4(i,j)))
end
end
if -1 < c < 1
if M3(:,:) > 0
M3 = -1
else M3(:,:) < 0
M3 = 1
end
elseif 0 < c < 2
I need to:You will need to then determine the probability of spin change. Use that probabilities in the table given
based on:Neighbors with Similar Spin 1 2 3 4 5 Prob. 0.98 0.85 0.50 0.15 0.02
This means that if c = 0 100% chance that the element in the same position as c in M3 sill change from 1 to -1 or -1 to 1
if c = 1, a 98% chance it will change, 2 an 85% chance, 3 a 50% cahnce, 4 a 15% chance and 5 a 2% chance
how do i do this
  댓글 수: 3
Hunter Herrenkohl
Hunter Herrenkohl 2018년 6월 18일
Actually that did work for what I am trying to do. I need to figure out the part after that.
Jan
Jan 2018년 6월 18일
편집: Jan 2018년 6월 18일
@Hunter Herrenkohl: No, -1 < c < 1 cannot do, what you want. Did you read Stephen's comment?
-1 < c is either true or false, which is equivalent to 1 or 0. Afterwards you compare this 1 0r 0 by < 1. This is valid Matlab code, but a weird formulation. Do you mean this instead:
|-1 < c & c < 1|
?

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

답변 (1개)

Jan
Jan 2018년 6월 18일
You apply a comparison to a matrix and use it as condition to an if command. But if requires a scalar condition. Therefore Matlab inserts an all() implicitly. To be exact:
if all(condition(:)) && ~isempty(condition)
You want something else - at least I guess this.
cond1 = (-1 < c & c < 1); % Not -1 < c < 1 !!!
cond2 = M3 > 0;
cond3 = M3 < 0;
M3(cond1 & cond2) = -1;
M3(cond1 & cond3) = 1;

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by