Vectorization problem with assignments

1 visualizzazione (ultimi 30 giorni)
Marcos il 16 Nov 2021
Risposto: Salman Ahmed il 19 Nov 2021
Good afternoon. I was trying to vectorize the following code in order to make it faster, however I was unable to do so. I can't also imagine about how to do it looking into the MATLAB examples of vectorization MATLAB. I would be very grateful if somebody could give me help about how to do it.
cols = zeros(length(vector1),dims);
for i=1:length(vector1)
cols(i,:) = Vector2(vector1(i),1:dims);
Thank you very much.
  1 Commento
David Hill
David Hill il 16 Nov 2021
Give examples of vector1, vector2, and desired output.

Accedi per commentare.

Risposte (1)

Salman Ahmed
Salman Ahmed il 19 Nov 2021
Hi Marcos,
You can use the following to vectorize your loop.
cols = Vector2(vector1,1:dims);


Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by