フィルターのクリア

For loop for multiple arrays

29 ビュー (過去 30 日間)
Vinay Srinivasan
Vinay Srinivasan 2019 年 10 月 6 日
コメント済み: Star Strider 2019 年 10 月 6 日
x= a+b+c
where a=[ 1 2 3 4], b=[5 6 7 8] and c =[9 10 11 12 ]
How to use for loop for this.
  2 件のコメント
meghannmarie
meghannmarie 2019 年 10 月 6 日
What do you want to loop on, what is the output you are looking for?
Vinay Srinivasan
Vinay Srinivasan 2019 年 10 月 6 日
I need value of x

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

採用された回答

Star Strider
Star Strider 2019 年 10 月 6 日
If you want ‘x’ to be the sum of the columns of the three vectors, try this:
a = [1 2 3 4];
b = [5 6 7 8];
c = [9 10 11 12];
for k = 1:size(a,2)
x(k) = a(k) + b(k) + c(k);
end
A loop is of course entirely unnecessary here. You can just do this instead to get the same result:
x = a + b + c
  2 件のコメント
Vinay Srinivasan
Vinay Srinivasan 2019 年 10 月 6 日
I have to determine fuel_consumption at 60,80 ,120 and maximum speed. Fuel consumption is function of sfc,powerclutch and speed which is varying and the rest are constant.How to use for loop in this condition istead of writing 4 times mtf.png
Star Strider
Star Strider 2019 年 10 月 6 日
I would do something like this:
sfcv = [600, 450, 330, 360]; % ‘sfc’ Vector
vel = [60, 80, 120, 420]; % ‘420’ Represents Maximum Speed, Since It Is Otherwise Undefined
for k = 1:numel(sfcv)
fuel_consumption(k) = sfc(k)*PowerClutch(k)*0.1/(1000*Rhofuel*vel(k));
end
figure
plot(vel, fuel_comsumption)
grid
xlabel('Velocity (km/h)')
ylabel('Fuel Consumption (L)')
Experiment to get the result you want.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by