Operations between every 2 different elements in a cell?

1 view (last 30 days)
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 Comments
Jan
Jan on 11 Jun 2018
What is operation? Why do you use curly braces in the first line and round parentheses afterwards?
Xiaohan Du
Xiaohan Du on 11 Jun 2018
Edited: Xiaohan Du on 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.

Sign in to comment.

Accepted Answer

Jan
Jan on 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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!