Using 'subs' in parallel for more than one equation

조회 수: 1 (최근 30일)
Tejas Adsul
Tejas Adsul 2018년 7월 6일
댓글: Tejas Adsul 2018년 7월 11일
I have 5 equations in an array: E = [E1;E2;E3;E4;E5]. Each equation is made of symbolic variables x1,y1. I now want to substitute these variables with x2,y2. Right now, I have this simple loop:
for i = 1:5
E(i) = subs(E(i),[x1,y1],[x2,y2]);
end
I was wondering if these substitutions could be carried out simultaneously for each equation, since they are independent of each other. Can I use parfor here, and if so, how should I modify my code?

답변 (1개)

Piotr Balik
Piotr Balik 2018년 7월 8일
Repmat is one of solutions:
E = subs(E,repmat([x1 y1],5,1),repmat([x2 y2],5,1))
Where 5,1 are 5-row 1-column copies of array [x1 y1].
  댓글 수: 1
Tejas Adsul
Tejas Adsul 2018년 7월 11일
This worked faster than the for loop. However, I tried removing the for loop:
E = subs(E,[x1,y1],[x2,y2]);
This works faster than repmat.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by