Azzera filtri
Azzera filtri

How to do this

2 visualizzazioni (ultimi 30 giorni)
Hunter Herrenkohl
Hunter Herrenkohl il 18 Giu 2018
Risposto: Jan il 18 Giu 2018
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 Commenti
Hunter Herrenkohl
Hunter Herrenkohl il 18 Giu 2018
Actually that did work for what I am trying to do. I need to figure out the part after that.
Jan
Jan il 18 Giu 2018
Modificato: Jan il 18 Giu 2018
@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|
?

Accedi per commentare.

Risposte (1)

Jan
Jan il 18 Giu 2018
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;

Community Treasure Hunt

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

Start Hunting!

Translated by