Operations between every 2 different elements in a cell?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
2018년 6월 11일
What is operation? Why do you use curly braces in the first line and round parentheses afterwards?
채택된 답변
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 Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!