I have a couple of questions. what is sliced variable? please bring a clear example. How should use parfor when you have a for inside another for loop?
Thanks

 채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 30일

1 개 추천

댓글 수: 2

Mohammad
Mohammad 2015년 6월 1일
편집: Mohammad 2015년 6월 1일
Example - How do use sliced variable in
CE=c./(absXini);
for i=1:m1
CE(i,i)=0;
end
if you want to see errors, simply add 'par' before for and read errors in details.
The documentation there makes clear that the loop index may only appear once in the indexing expression; your code tries to use it twice.
Equivalent code that can be run with parfor, presuming a square 2D array
for i = 1 : size(CE,1)+1 : (m1-1)*size(CE,1)+m1
CE(i) = 0;
end
Other equivalent:
t = zeros(m1,1);
for i = 1 : m1
t(i) = 0; %redundant in the case of 0
end
CE(1:size(CE,1)+1:(m1-1)*size(CE,1)+m1) = t; %must be outside
And there is the vector version (not usable inside parfor)
CE(sub2ind(size(CE),1:m1,1:m1)) = 0;
Some of these can be simplified for the case where m1 is the same as size(CE,1) and the matrix is square, including
CE = CE - diag(diag(CE));

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 5월 30일

댓글:

2015년 6월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by