I intend to write a value, say, 90, in many times, say 15 (actually want it in 1440 times) inside a parfor loop.
The first approach using for loop generated this error - 'valid indices for 'a' are restricted in PARFOR loop'
parfor n=1:35
a=zeros(:,15); % the variable is indexed but not sliced
for k=1:15
a(:,k)= 100
end
end
the second approach (vectorization)
parfor n = 1:35
a=zeros(:,15); % the variable is indexed but not sliced
a(:,1:15)=90;
end
generated same error and so PARFOR loop cannot run due to the way variable 'a' is used.
I want to actually slice the variable 'a' not just indexed so as to avoid unnecessary communication overhead, please how do I go about this? Kindly assist.
Felix

 採用された回答

Edric Ellis
Edric Ellis 2012 年 1 月 16 日

0 投票

To slice the variable 'a', you need to use a subscript list that contains:
  1. One instance of the loop variable
  2. Other subscripts which are either constant literal values or ':'
So, for example, in the following case, 'a' will be a sliced output:
parfor n = 1:35
tmp = 90 * ones(1, 15);
a(n, :) = tmp;
end
which creates 'a' as a 35x15 matrix with each element containing the value 90.

1 件のコメント

Facosoft
Facosoft 2012 年 1 月 17 日
Thanks

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 1 月 16 日

0 投票

zeros(:,15) is not valid syntax to call the zeros() function.

1 件のコメント

Facosoft
Facosoft 2012 年 1 月 17 日
Thanks

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by