Copy many to one elements within arrays

If I execute:
x = zeros(1,5);
x([1, 2, 3, 1, 4, 5]) = (1:6);
then I get x = (4, 2, 3, 5, 6). Here x(1) is written twice. And the second write takes precedence. My question: " Is it guaranteed that the write corresponding to last occurrence of an index takes precedence? ". I can imagine that on some platforms, copying may be implemented in reverse order, and I would get different results. In my application, I need to ensure a particular deterministic behavior, but I also need to be as efficient as possible.

1 comentario

Guillaume
Guillaume el 20 de Nov. de 2014
I don't think it's documented anywhere, so the best thing would probably be to raise a support ticket with mathworks to get an official answer.

Iniciar sesión para comentar.

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 20 de Nov. de 2014

0 votos

What platforms? It appears that Matlab will assign values in ascending order

2 comentarios

Raghavan
Raghavan el 20 de Nov. de 2014
I agree that in x86 architectures, the current version of MATLAB seems to assign values in ascending order. But I have not seen documentation that this will always be the case on all platforms. My understanding is that this array copy is a built-in function of MATLAB, which is probably implemented in low level assembly language. This implementation could be machine dependent. On some processor architectures, it may be more efficient to copy in descending order. On some other multi core systems, different segments of the array could be copied in parallel to speed things up. Each of these could lead to a different result. I may be paranoid here, but I don't want to be surprised later if we migrate to a new platform or new version of MATLAB.
Azzi Abdelmalek
Azzi Abdelmalek el 20 de Nov. de 2014
Editada: Azzi Abdelmalek el 20 de Nov. de 2014
I don't think that how Matlab does assignment depends on other platforms.

Iniciar sesión para comentar.

Categorías

Más información sobre Elementary Math en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Nov. de 2014

Comentada:

el 20 de Nov. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by