Multidimensional algorithmic array loop

5 ビュー (過去 30 日間)
MR T
MR T 2016 年 12 月 4 日
回答済み: Edric Ellis 2016 年 12 月 5 日
Lets say I have a m*n matrix called v, and I want to store algorithmic values to each element in v. Perhaps for spot v(1,1) I want to store v(1,1,1) = m-n and v(1,1,2) = m+n. Could this be accomplished by a parfor loop?
For example:
parfor x = 1:m
for y = 1:n
v(m,n,1) = m-n
v(m,n,2) = m+n
end
end
  1 件のコメント
KSSV
KSSV 2016 年 12 月 4 日
Why loop when m,n remains fixed in loop? Your question is not clear.

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

回答 (1 件)

Edric Ellis
Edric Ellis 2016 年 12 月 5 日
I imagine you meant to index v using the loop variables. In which case, you need to rearrange things to ensure there's only a single assignment into v, like so:
m = 7; n = 4;
parfor x = 1:m
for y = 1:n
v(x,y,:) = [m-n, m+n]
end
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by