parfor - how do I "slice" a variable? Can I?

8 次查看(过去 30 天)
Michael
Michael 2011-11-25
I have a parfor loop that takes one row of a matrix and uses it for calculations.
I therefore am getting errors since I am calling this variable inside the iteration by writing "b = B(i,:)" to get the ith row. What do I do? I understand the problem, each worker is having to read B to find what b is, but I have no clue what to do to fix it or if anything even can be fixed.
Thanks for any help Mike
  2 个评论
Daniel Shub
Daniel Shub 2011-11-26
What error are you getting? I don't see why
b = B(i, :)
would cause an error, unless you are running out of memory.
Edric Ellis
Edric Ellis 2011-11-28
Any chance you could post a self-contained example? "B(i,:)" should allow the variable B to be sliced, unless you're using B in some other way.

请先登录,再进行评论。

回答(1 个)

Hin Kwan Wong
Hin Kwan Wong 2011-11-28
Make sure the following requirements are satisfied:
  • Type of First-Level Indexing — The first level of indexing is either parentheses, (), or braces, {}.
  • Fixed Index Listing — Within the first-level parenthesis or braces, the list of indices is the same for all occurrences of a given variable.
  • Form of Indexing — Within the list of indices for the variable, exactly one index involves the loop variable.
  • Shape of Array — In assigning to a sliced variable, the right-hand side of the assignment is not [] or '' (these operators indicate deletion of elements).
For exacmple, you might have other instances where B is referenced with different indices not as B(i,:) (point 2)

类别

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