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.
3 Comments
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/653923-how-to-vectorize-this-for-loop#comment_1147603
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/653923-how-to-vectorize-this-for-loop#comment_1147603
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/653923-how-to-vectorize-this-for-loop#comment_1147618
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/653923-how-to-vectorize-this-for-loop#comment_1147618
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/653923-how-to-vectorize-this-for-loop#comment_1147648
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/653923-how-to-vectorize-this-for-loop#comment_1147648
Sign in to comment.