How to assign a constant to a submatrix without a loop

2 ビュー (過去 30 日間)
Ben Kaye
Ben Kaye 2020 年 4 月 29 日
編集済み: Adam Danz 2020 年 5 月 4 日
Is this possible without a for loop? Sample code:
%A is an (m x n) matrix m,n > 2
A(2:end-1,2) = 67.5*ones(size(A(2:end-1,2)));
I so far can not make this work.
  1 件のコメント
Adam Danz
Adam Danz 2020 年 4 月 29 日
編集済み: Adam Danz 2020 年 4 月 30 日
What's the problem with the code in your question other than that it can be simplified (see answer)?
A =
5 4 9 2 8 8
1 6 1 10 7 3
2 5 8 4 4 8
8 6 1 10 9 6
6 9 3 2 5 7
>> A(2:end-1,2) = 67.5*ones(size(A(2:end-1,2)))
A =
5 4 9 2 8 8
1 67.5 1 10 7 3
2 67.5 8 4 4 8
8 67.5 1 10 9 6
6 9 3 2 5 7

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

採用された回答

Adam Danz
Adam Danz 2020 年 4 月 29 日
編集済み: Adam Danz 2020 年 5 月 4 日
A = magic(9) % demo matrix
A(2:end-1,2) = 67.5;
result
A(2:end-1,2) = 67.5
A =
47 58 69 80 1 12 23 34 45
57 67.5 79 9 11 22 33 44 46
67 67.5 8 10 21 32 43 54 56
77 67.5 18 20 31 42 53 55 66
6 67.5 19 30 41 52 63 65 76
16 67.5 29 40 51 62 64 75 5
26 67.5 39 50 61 72 74 4 15
36 67.5 49 60 71 73 3 14 25
37 48 59 70 81 2 13 24 35

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by