行列の範囲指定の書き方

19 ビュー (過去 30 日間)
彩乃
彩乃 2023 年 11 月 14 日
コメント済み: Atsushi Ueno 2023 年 11 月 14 日
f=10*x(1,:)+5*(2,:)
のx(1,:)と(2,:)に出てくる数値を0.1から10に範囲を設定したい時、xmとxMはそれぞれどのように書けばいいですか?
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 14 日
What is the objective here?
What are xm and xM?
Atsushi Ueno
Atsushi Ueno 2023 年 11 月 14 日
どういう状況ですか?目一杯想定してみましたが、何を計算したいのか良くわかりません
x = 20 * rand(2,10) - 5 % 適当な値で行列 x を作成(xの範囲は-5~15)
x = 2×10
2.6424 0.1530 4.9814 0.8633 0.8156 7.3554 13.2246 2.6418 -4.6864 6.9958 11.1236 3.5038 7.7657 -0.2480 3.9032 -2.6194 3.9562 2.1639 5.7136 12.9850
temp = 0.1 <= x & x <= 10 % 0.1~10 の要素に 1 、それ以外に 0 をインデックス付け
temp = 2×10 logical array
1 1 1 1 1 1 0 1 0 1 0 1 1 0 1 0 1 1 1 0
xm = temp(1,:) % 1行目の0.1~10インデックスがxmで、
xm = 1×10 logical array
1 1 1 1 1 1 0 1 0 1
xM = temp(2,:) % 2行目の0.1~10インデックスがxMという事ですか?
xM = 1×10 logical array
0 1 1 0 1 0 1 1 1 0
f = 10 * x(1,xm) + 5 * x(2,xM) % 0.1~10の要素数が合わないから加算出来ません!
Arrays have incompatible sizes for this operation.

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

回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!