How to Save info of two matrix in another matrix, and then calculate the distance between positions of the matrix?

1 Ansicht (letzte 30 Tage)
Hello,
I have two matrix Present and Future. Both are 3600x3600 and are filled with 0,1 and 2. 0 means ocean, 1 land and 2 presence of a specie. The future matrix is a projection so it has more 2s in the matrix.
I want to calculate within loops the following:
Get a new matrix (Difference) that tells me which positions in the Future are now occupied by the specie that werent occupied in the Present.
Then pick randomly in this new matrix Difference a newly occupied cell, and then calculate the distance of this cell with the positions of the occupied cells in the Present.
By distance I mean calculate the difference of rows and columns,(between the picked cell and all the Present occupied positions) and then with that apply pitagoras to get the linear distance.
And finally I want to show which is the smallest distance.
Hope you can help me!

Antworten (1)

Geoff Hayes
Geoff Hayes am 6 Apr. 2017
Alecd - what have you tried so far? There are several ways to determine which elements of your future matrix, F, have a two that is not a two in the present matrix, P. For example,
F = randi(3,3600,3600) - 1;
P = randi(3,3600,3600) - 1;
FS = F==2; % future species
PS = P==2; % present species
FS and PS are logical matrices where a one indicates that the element has a two and a zero otherwise. Since you are only interested in the ones (or "trues") of FS that are not a true in PS, then you could do
NFS = FS == 1 & FS ~= PS; % new future species
You can verify this by considering
F(NFS)
which should return all of the twos in your future matrix and
P(NFS)
which should return ones and zeros from your present matrix.
As this seems like homework, I'll leave the rest for you. You can use randi to randomly a row and column (index) from the new species of the future and then calculate its distance to each of the species from the present.

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by