Vectorization problem with assignments

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);
end
Thank you very much.
Marcos

댓글 수: 1

David Hill
David Hill 2021년 11월 16일
Give examples of vector1, vector2, and desired output.

댓글을 달려면 로그인하십시오.

답변 (1개)

Salman Ahmed
Salman Ahmed 2021년 11월 19일

0 개 추천

Hi Marcos,
You can use the following to vectorize your loop.
cols = Vector2(vector1,1:dims);

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

질문:

2021년 11월 16일

답변:

2021년 11월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by