# Operations between every 2 different elements in a cell?

조회 수: 1(최근 30일)
Xiaohan Du 11 Jun 2018
Commented: Xiaohan Du 11 Jun 2018
Hi all,
I have a cell like this:
K>> ur
ur =
4×3 cell array
{[1]} {'-1 -1'} {1×201 cell}
{[2]} {'1 -1' } {1×201 cell}
{[4]} {'1 1' } {1×201 cell}
{[3]} {'-1 1'} {1×201 cell}
I'd like to perform some operations between every 2 elements of the 3rd column of ur, manually be like this:
operation(ur{1, 3}, ur{2, 3}) % 1 and 2
operation(ur(1, 3), ur(3, 3)) % 1 and 3
operation(ur(1, 3), ur(4, 3)) % 1 and 4
operation(ur(2, 3), ur(3, 3)) % 2 and 3
operation(ur(2, 3), ur(4, 3)) % 2 and 4
operation(ur(3, 3), ur(4, 3)) % 3 and 4
The number of cell rows is not limited to 4. Is there a way to do this in a loop? Or whatever automatic? I think I just need to pick the correct index to perform the operation, but how?
Many thanks!
Edit: the operations should all be curly brackets:
operation(ur{m, 3}, ur{n, 3}) % m and n

#### 댓글 수: 2

Jan 11 Jun 2018
What is operation? Why do you use curly braces in the first line and round parentheses afterwards?
Xiaohan Du 11 Jun 2018
My mistake, it should all be curly brackets. Operation here is a function in my code, this function takes ur{m, 3} and ur{n, 3} and gives a matrix as a result.

로그인 to comment.

### 채택된 답변

Jan 11 Jun 2018
Maybe you mean:
index = nchoosek(1:4, 2);
for k = 1:size(index, 1)
operation(ur{index(k, 1), 3}, ur{index(k, 1), 3});
end

#### 댓글 수: 1

Xiaohan Du 11 Jun 2018
Thanks Jan!

로그인 to comment.