Vectorising a piece of Code

조회 수: 8 (최근 30일)
hemant
hemant 2016년 11월 20일
답변: Image Analyst 2016년 11월 20일
I have a matrix, mainMatrix of nan values and I also have three vectors of same length, rowVector: Stores the row Number. LeftColVector:Stores the left-column numbers. RightColVector: Stores the right-column numbers. What I need to do is something like this,
for i=1:length(rowVector)
mainMatrix(rowNumber(i),LeftColVector(i):RightColVector(i))= %Some values from another cell array{i}%
end
Is there a way to vectorise this code?

답변 (1개)

Image Analyst
Image Analyst 2016년 11월 20일
It's already partially vectorized, going along columns. I don't know of anyway to vectorize it with rows in a single line of code. Anyway, unless you have hundreds of millions of iterations, the for loop method you have should be very fast. Go ahead and time it and you'll see.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by