how can we overcome the buffer limitations in octave?
when we tried to implement a program with one for loop with a limit of 100,octave faile开发者_JAVA百科d to show all the results.this is the problem with buffer. how can we overcome that?
Try to express the problem in terms of matrices. MATLAB and Octave are optimized for matrix operations. Here is an excerpt of what the MATLAB documentation site says about vectorizing loops:
The MATLAB software uses a matrix language, which means it is designed for vector and matrix operations. You can often speed up your code by using vectorizing algorithms that take advantage of this design. Vectorization means converting
for
andwhile
loops to equivalent vector or matrix operations.
They also provide a simple example of vectorizing a loop to compute the sine of 1001 values ranging from 0 to 10:
i = 0;
for t = 0:.01:10
i = i + 1;
y(i) = sin(t);
end
To a vectorized version of the same code:
t = 0:.01:10;
y = sin(t);
There are more details in the MATLAB Code Vectorization Guide and some examples in these few related questions:
- Loopless function calls on vector/matrix members in Matlab/Octave
- Matlab - Speeding up a Nested For Loop
精彩评论