行列の範囲指定の書き方

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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!