필터 지우기
필터 지우기

Indexing element while using parfor

조회 수: 1 (최근 30일)
balandong
balandong 2016년 12월 9일
댓글: balandong 2016년 12월 9일
Objective: Index the matrix such as shown in the picture using parfor
Dear coder, say there are 3 variables (a,b,c) with varying value (a=1:4), (b=1:5), and (c=1:6) computed using a function output = a + c + d. To enhance efficiency, parfor was used.
However, I am having difficulties to index the variable and output as shown in the above picture. Similar result can be obtain by using typical for-loop. I wonder, what modification should be made to remedy this?
Code using for-loop
X=cell(4,5,6);
iterations=size(X);
answer_me = zeros (120,4);
for ix=1:prod(iterations)
[a,b,c]=ind2sub(iterations,ix);
answer_me (ix,1:4)=[a b c (parfor_function(a,b,c))];
end
The parfor_function
function [ answer_a ] = parfor_function( a,b,c )
answer_a = a + b + c;
end
Thanks in advance.
  댓글 수: 2
KSSV
KSSV 2016년 12월 9일
parfor_function...? what is this?
balandong
balandong 2016년 12월 9일
The parfor_function
function [ answer_a ] = parfor_function( a,b,c )
answer_a = a + b + c;
end

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

채택된 답변

KSSV
KSSV 2016년 12월 9일
Use
answer_me(ix,:)=[a b c (parfor_function(a,b,c))];
instead of
answer_me (ix,1:4)=[a b c (parfor_function(a,b,c))];
  댓글 수: 1
balandong
balandong 2016년 12월 9일
Thanks KSSV, appreciate it

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

추가 답변 (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