Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Evaluate cell array using matrix

Tags:

matrix

matlab

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.

like image 860
lawrence Avatar asked Dec 12 '25 11:12

lawrence


1 Answers

 fun = @(c) Y(c(1), c(2));
 X = cellfun(fun, Z)
like image 136
mbschenkel Avatar answered Dec 15 '25 08:12

mbschenkel