How to vectorize this for loop

How to vectorize this for loop
%%% F is array of float
%%% SD is two dimension array of float
for i=1:10
F(i) = SD(i,:);
end

3 Kommentare

David Hill
David Hill am 19 Nov. 2020
You need to provide the Fin() function. With a loop of only 10, why do you want to vectorize?
Star Strider
Star Strider am 19 Nov. 2020
Master Blabla
Master Blabla am 19 Nov. 2020
Bearbeitet: Master Blabla am 19 Nov. 2020
F

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 19 Nov. 2020

0 Stimmen

Fea = Fin( sub2ind(size(Fin), SD(1:10,:), 20*ones(10, size(SD,2))));
However, your original code would have failed. Your SD is 2d, so SD(i,:) would have been a vector of values, and indexing FD() with a vector of row indices and one column index would return a vector of values rather than a single value -- and so you would not be able to store it into the scalar location Fea(i) .
The only way for your code to work would be if SD were a column vector instead of a 2D array.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 19 Nov. 2020

Bearbeitet:

am 19 Nov. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by