Utilizing Matlab for 2 "for loop" calculation

조회 수: 1 (최근 30일)
Murat
Murat 2014년 6월 29일
답변: Murat 2014년 6월 29일
Hi
I have two for loops, in which I am calculating my functions. I call many function inside of it and results of those functions are 2x2 matrices. Ex:
for m = 1:100
for n = 1:500
func1Result = func1(m,n,...); % Result is a 2x2 matrix
func2Result = func2(m,n,funct1Result..); %Result is a 2x2 matrix
..
Result1 = funcxResult1*funcxResult2*...;
...
end
end
However, the code is not efficient as I have 2 for loops. I want to utilize Matlab's linear operation advantage. However, I could not come up a solution about it. How can I do that so that I can fasten my computation?
Regards

채택된 답변

Murat
Murat 2014년 6월 29일
I found a way to do it. I spent most of the time to calculate bessel functions which are inside of my func1,func2 etc.My code runs for 5 min. But, if I calculate all bessel function and assign it to a matrix, then my code runs 45 sec. I use again 2 for loops. But, calculation is now faster.

추가 답변 (1개)

dpb
dpb 2014년 6월 29일
Presuming only the last result is actually needed...
[x y]=meshgrid(1:M,1:n);
result=func2(x,y,func1(x,y));
  댓글 수: 1
Murat
Murat 2014년 6월 29일
Thanks for your answer. However, when I use meshgrid, I cannot multiply those submatrices -which are 2x2-. I would again have to use for loops to multiply my 2x2 submatrices.

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

카테고리

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