Multi-level indexing

조회 수: 2 (최근 30일)
mutt
mutt 2011년 9월 7일
Given: screen(1).position = [1 2; 3 4]; screen(1).size = [5 6; 7 8]; screen(2).position = [11 12; 13 14]; screen(2).size = [15 16; 17 18]; I can execute: screen(1).position(:,2) and screen(1:2).position but not screen(1:2).position(:,2), for example to make a simultaneous assignment to the 2nd columns of the position matrices i.e. intuitively I would like to say: screen(1:2).position(:,2) = [19 20; 21 22]; What is the easiest way to accomplish the assignment?

채택된 답변

Oleg Komarov
Oleg Komarov 2011년 9월 7일
This is alimitation of structures:
new = [19 20; 21 22];
for n = 1:numel(screen)
screen(n).position(:,2) = new(:,n);
end
If your fields concatenable, then I would suggest to store them as:
screen.position = cat(3,[1 2; 3 4], [11 12; 13 14]);
screen.position(:,2,:) = [19 20; 21 22];
  댓글 수: 1
mutt
mutt 2011년 9월 7일
Thank you very much.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by