iterating with predefined submatrix range

2 ビュー (過去 30 日間)
현우
현우 2022 年 11 月 27 日
コメント済み: Matt J 2022 年 11 月 27 日
section_1 = {[10:15, 6:18], [9:15, 6:20], [12:13, 34:36]};
for [i, j] = section_1
T(i,j, k + 1) = t_human *(T(i,j-1) + T(i-1,j) + T(i+1,j) + T(i,j+1)) + (1- 4* t_human) * T(i,j,k);
end
I want to iterate submatrices of matrix T, and predefined the row and column of submatrix in section_1.
I want to get each item of the section_1 and assign the value into [i, j] so that I can easily calculate the formula inside the for loop.
However, I get error.
  1 件のコメント
Jan
Jan 2022 年 11 月 27 日
This is no valid Matlab syntax. Neither the Matlab interpreter nor the readers can guess, what you want.
[10:15, 6:18] % is the same as:
[10, 11, 12, 13, 14, 15, 6, 7, 8, 9, 10, ... 18]
Therefore it is not clear, what you call "item of the section_1".
This is no valid for loop:
for [i, j] = section_1
Whenever you menation an error, read the error message carefully. If this does not allow for finding a solution already, post a copy of the complete message. Do not let the readers guess, which message you get.
Unfortunately your text description of what you want to achive is not really clear. The code has no valid Matlab syntax. Therefore answering the question needs a lot of bold guessing.
T(i,j, k + 1) means, that T is a 3 dimensional array, but T(i,j-1) looks like a 2D array.
Please post some inputs, explain the procedure and a small example for the wanted output.

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

回答 (1 件)

Matt J
Matt J 2022 年 11 月 27 日
編集済み: Matt J 2022 年 11 月 27 日
section_1 = {10:15, 6:18; 9:15, 6:20; 12:13, 34:36}';
for s = section_1
[i,j]=deal(s{:});
T(i,j, k + 1) = t_human *(T(i,j-1) + T(i-1,j) + T(i+1,j) + T(i,j+1)) + (1- 4* t_human) * T(i,j,k);
end
  2 件のコメント
Jan
Jan 2022 年 11 月 27 日
What is the purpose of:
[i, j] = deal(s{:})
Because s is a scalar struct containg a vector, i and j have the same value afterwards.
Matt J
Matt J 2022 年 11 月 27 日
Yes. I fixed it.
section_1 = {10:15, 6:18; 9:15, 6:20; 12:13, 34:36}';
for s = section_1
[i,j]=deal(s{:});
i,j
end
i = 1×6
10 11 12 13 14 15
j = 1×13
6 7 8 9 10 11 12 13 14 15 16 17 18
i = 1×7
9 10 11 12 13 14 15
j = 1×15
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
i = 1×2
12 13
j = 1×3
34 35 36

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by