Operations between every 2 different elements in a cell?

조회 수: 1 (최근 30일)
Xiaohan Du
Xiaohan Du 2018년 6월 11일
댓글: Xiaohan Du 2018년 6월 11일
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
Jan 2018년 6월 11일
What is operation? Why do you use curly braces in the first line and round parentheses afterwards?
Xiaohan Du
Xiaohan Du 2018년 6월 11일
편집: Xiaohan Du 2018년 6월 11일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2018년 6월 11일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by