Matrix Help

1 view (last 30 days)
Euan
Euan on 24 Nov 2011
I have a matrix similar to the following
C = 1 2 4 5
3 4 5 6
6 4 2 1
each of these values have been calculated as a function of x and y. Say
x = a b c d
y = f g h
This corresponds to x as so
C = 1(f, a) 2(f, b) 4(f, c) 5(f, d)
3(g, a) 4(g, b) 5(g, c) 6(g, d)
6(h, a) 4(h, b) 2(h, c) 1(h, d)
Say I want to get the corresponding x and y values for a value in C, how would I do this?
  1 Comment
Jan
Jan on 24 Nov 2011
The question is not getting clear to me.
E.g. if you have 6 as input, what is the expected output? What do the symbols "a", "b", "c" etc mean? Are they numbers, indices, symbolic expressions, functions?

Sign in to comment.

Answers (2)

David Young
David Young on 24 Nov 2011
As Jan comments, your question is not clear. Like him, I can't understand the role of the symbols a, b etc. which just seem to correspond to the subscripts for the matrix, with a=1, b=2, c=3, d=4, f=1, g=2, h=3. If so, they are redundant, and it's simpler to use numerical subscripts.
Guessing a bit, perhaps your question is simply asking what the subscripts are for a particular value in C. So C(3) is at x=1, y=2. If that's right, the answer is this:
[y, x] = find(C == 3)
which returns the x and y coordinates for the value 3. Note the reversal in order of y and x in the results list. If you use 6 rather than 3 you will get vectors for x and y each with 2 subscripts, because 6 is found at x=4,y=2 and also at x=1,y=3.
If you were asking something more complex, please clarify.

Andrei Bobrov
Andrei Bobrov on 24 Nov 2011
e.g.
i1 =[4 16 14 11]
j1 =[8 1 4]
x =[5 -6 -2 2
0 -11 -8 -4
6 -8 -8 -6]
f1 = @(i1,j1)bsxfun(@minus,bsxfun(@plus,x,i1),j1')
C = f1(i1,j1)

Community Treasure Hunt

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

Start Hunting!