Selecting element at same position in a matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
VID1 is a 3x3 cell. I choose a value randomly from the cell like thus.
ID1=VID1{ randi([1,size(VID1,1)],1), randi([1,size(VID1,2)],1 )};
If I have randomly chosen element VID{1,1}. I want to choose an element in the same position in another cell Vehicle1 (3x3 cell). How can I do this?
댓글 수: 0
채택된 답변
Jan
2021년 4월 13일
편집: Jan
2021년 4월 13일
If you need the indices again, store them in variables:
i1 = randi([1, size(VID1, 1)]);
i2 = randi([1, size(VID1, 2)]);
ID1 = VID1{i1, i2};
V1 = Vehicle1{i1, i2};
It might be easier to use linear indices:
index = randi([1, numel(VID1)]);
ID1 = VID1{index};
V1 = Vehicle1{index};
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!