Selecting element at same position in a matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Joel Schelander
el 13 de Abr. de 2021
Comentada: Joel Schelander
el 13 de Abr. de 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 comentarios
Respuesta aceptada
Jan
el 13 de Abr. de 2021
Editada: Jan
el 13 de Abr. de 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 comentario
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!