4/6/2023 0 Comments Octave for loop![]() I want an alternative way to do this which should be faster than this. This means that Octave proceeds immediately to the. Even if the matrix is in 3d shape, octave still loop over it column by column (not 2d matrix for each loop). When the remainder is zero in the first while statement, Octave immediately breaks out of the loop. If var is a column vector or a matrix, var will be a column vector each time the loop body is executed. Here column 1 of first element of A is equal to column 1 of first element of B,even the second column hence I can take the third element of B, but for the second element of column 1 is equal in A and B ,but second element of column 2 is different ,here it should search for that element and print the element in the third column,and am doing this with for loop which is very slow because of larger dimension.In mine actual problem I have given for loop as written below: for k=1:37651 It means that octave for loop will only iterate column by column, no matter about the dimensions. Thank u, but this will work only if both elements in both the rows are equal.For example my matrices are like this, A= And then it needs to copy over all previous elements each pass through the loop. That in turn means MATLAB needs to reallocate a new vector of length one element longer than the last, at EVERY iteration. Because size of matrices is very large.Please suggest some alternative way so that I can reduce my time and computation. That forces MATLAB to grow the vector in length every pass through the loop. ![]() ![]() You can compare matrices/vectors and the result is a matrix/vector of 0/1 again: > A (:,1) B. A (:,1) selects the first column of a matrix. You should try commands and inspect intermediate results in the interactive shell to see how they fit together. I have to compare a particular column of a one matrix with the other(my matrix A is containing more than 5 variables, similarly matrix B is containing the same.) and if elements in column one of matrix A is equal to elements in the second matrix B then I have to use the third column of second matrix B to compute certain values.I am doing this with octave by using for loop, but it consumes a lot of time to do the computation for single day, i have to do this for a year. You should work with complete matrices or vectors whenever possible.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |