# Operations between every 2 different elements in a cell?

1 visualizzazione (ultimi 30 giorni)
Xiaohan Du il 11 Giu 2018
Commentato: Xiaohan Du il 11 Giu 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 CommentiMostra NessunoNascondi Nessuno
Jan il 11 Giu 2018
What is operation? Why do you use curly braces in the first line and round parentheses afterwards?
Xiaohan Du il 11 Giu 2018
Modificato: Xiaohan Du il 11 Giu 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.

Accedi per commentare.

### Risposta accettata

Jan il 11 Giu 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 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Xiaohan Du il 11 Giu 2018
Thanks Jan!

Accedi per commentare.

### Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by