Selecting element at same position in a matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Joel Schelander
am 13 Apr. 2021
Kommentiert: Joel Schelander
am 13 Apr. 2021
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 Kommentare
Akzeptierte Antwort
Jan
am 13 Apr. 2021
Bearbeitet: Jan
am 13 Apr. 2021
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};
1 Kommentar
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!