I have a n by n cell Z where the (i,j) component of Z is an ordered pair (s,t).
I then have some matrix Y. Basically each component of Z contains a coordinate using which I am trying to locate an element of Y. In other words, I am trying to return a n by n matrix X where X(i,j) = Y(s,t).
Here is a specific example:
suppose n = 3,
Z = {[1 1] [2 1] [2 2];
[1 1] [1 3] [3 3];
[3 2] [3 1] [2 4]}
Y = [1 2 3 5;
2 3 5 7;
1 0 4 6]
I am trying to get a 3 by 3 matrix that gives, in this example,
[1 2 3;
1 3 4;
0 1 7]
I've tried to use Z = squeeze(num2cell(permute(cat(3,A,B),[3,1,2]),1)) to create Z from two other matrices A and B, but I am stuck with the question I have.
fun = @(c) Y(c(1), c(2));
X = cellfun(fun, Z)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With