Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
-Try to use function provided by matlab as much as possible, since some of them are not implemented as mfiles but as dll's. It will run a lot faster than trying to implement it with elementary matlab operations.
-Or what you can do is to replace loop with some matrix operations if possible. If it is not possible and it is unacceptably slow, write it in C or C++ and make function calls to matlab when necessary(or the other way around implement loop in C/C++ and having matlab make function calls.)
One thing to remember about MATLAB is that loops make your programs run extremely slow. Especially if they are nested.
Aviod using loops and go for some sort of matrix manipulation techniques. If u want to access a certain element in a specific row in a matrix for example.....dont put it in a for loop and access each row one by one......the loops will slow down the entire process especially if your matrix is a big one. Try acessing that particular element directly.Hope this helps.
Best way of course is to avoid loops. But you must have this in mind: Matlab is a matrix oriented tool. So the more you use matrixes the more you speed up the computations. Try to convert a loop using matixes ie by calling a matrix instead getting in a lopp. The other thing for speeding up computation is to define the dimentions of the matrix. Don't let Matlab compute the dimension. Define a matrix ie M(3,4) whenever you want to use it. I think these will help. Of course you can allways use C++ : Matlab is build it on C++ packages. So, if you can't avoid loops, then it is better to use C++. In my case, a programm in Matlab wanted ~2h to run and gave me the 1/5 of the results than the same programm in C++ with the speed of ..5min!!! It is up to you my boy!
D.
In MATLAB programming there is a very important rule: Whenever the loop counter is used just as a counter and is not involved in the computations inside the loop, the loop can be replaced by Matrix operation
for example
x = 101:200
for n = 1:100
y[n] = x[n] ^ 2;
end
Because Matlab is an interpreted language, it must interpret every line in a for loop each time it goes through the loop. This makes Matlab painfully slow at doing loops.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.