フィルターのクリア

loop and mixing solution

2 ビュー (過去 30 日間)
addy fang
addy fang 2020 年 7 月 27 日
コメント済み: addy fang 2020 年 7 月 27 日
Variables A, B, C each varies from 0 to 100, and their sum equal to 100.
How should I do it?
I was trying to run this:
for A, B, C = 0:10:100, A+B+C=100,
z=A*0.1+B*0.2+C*0.3
end
It did not work. Apparently.

採用された回答

KSSV
KSSV 2020 年 7 月 27 日
A = 0:10:100 ;
B = A ;
C = A ;
[A,B,C] = meshgrid(A,B,C) ;
% convert them to columns
A = A(:) ; B = B(:) ; C = C(:) ;
% get the sum
thesum = A(:)+B(:)+C(:) ;
% get the indices whos sum isequal to 100
idx = thesum==100 ;
% pick the values
A = A(idx) ; B = B(idx) ; C = C(idx) ;
% ge the required Z
Z = 0.1*A+0.2*B+0.3*C ;
  1 件のコメント
addy fang
addy fang 2020 年 7 月 27 日
Thank you. That works!
One more question, if I need to get z from a few tables, can I do the following?
If Variables A, B, C each varies from 0 to 100, and their sum equal to 100.
for A, B, C = 0:10:100, A+B+C=100,
z=A*T1.+B*T2.+C*T3.
end
T1, T2, T3 are tables, containing similar structures (same columns/rows, similar type of data)

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by