Vector indexing inefficiency question.

조회 수: 1 (최근 30일)
Daniel
Daniel 2014년 6월 3일
댓글: Daniel 2014년 6월 3일
Hi all,
I am having performance issues with matlab and I was wondering if anybody had any ideas to speed up my algorithm
I have four vectors, a,b,c,d each of varying lengths. Each value inside the vectors represents a particular angle.
a = [1 2 3 5]
b = [2 52 53 51 55 66]
c = [1]
d = [3 6 9]
A set of four values from A, B, C, D represents a particular geometry I need to evaluate. For example, [1 52 1 9] is a geometry [2 2 1 6] is a geometry etc.... I need to do this for every possible combination of geometry available.
currently I have a bunch of nested for loops, and while I know this is inefficient, it helps me for debugging and I wasn't sure how to vectorize when you need to do each geometry, especially when the vectors are of varying lengths.
Anybody have any good ideas?
Thanks,
Dan
  댓글 수: 2
Rick Rosson
Rick Rosson 2014년 6월 3일
Please post your MATLAB code.
Daniel
Daniel 2014년 6월 3일
a = [1 2 3 5]
b = [2 52 53 51 55 66]
c = [1]
d = [3 6 9]
for i = 1:length(a)
for j = 1: length(b)
for k = 1: length(c)
for r = 1: length(d)
data = function( a(i), b(j), c(k) d(r) )
end
end
end
end
What I'm trying to do is get rid of these for loops

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

채택된 답변

Mahdi
Mahdi 2014년 6월 3일
Have you looked at perms built-in function? I'm sure you can manipulate to fulfill your need.
  댓글 수: 2
Daniel
Daniel 2014년 6월 3일
That's what I'm looking for. thank you.
Mahdi
Mahdi 2014년 6월 3일
No problem.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by