Adding new values to an array using a loop

Currently I am trying to write a code in MatLab (still learning, beginner). Below you can see the code I have written so far. For each axle an row of 5 values in the array is reserved for the parameters for each axle. (so the parameters of one axle is stored on the same line). Now I am trying to store the values in the array for each axle on a separate row. Somehow no rows are added to the array and the array size is still (1,5) instead of (n_axle,5). (n_axle value is defined by the user). What am I doing wrong and how could I solve this problem? I know I am pretty close, but I just can't find out where I went wrong. Thanks.
n_axles = input('define amount of axles');
count=0; j=0;
while count ~= n_axles
wheel_parameters = zeros(n_axles,5); %create # vector for # axles
for j = 1:n_axles
parameters1 = input('define load (kg)');
parameters2 = input('define pressure (kpa)');
parameters3 = input('recommended pressure (kpa)');
parameters4 = input('define width (m)');
parameters5 = input('define diameter (m)');
wheel_parameters = [parameters1, parameters2, askparameters3, parameters4, parameters5]
j = j + 1;
end
count= count + 1;
end

 採用された回答

MathReallyWorks
MathReallyWorks 2017 年 5 月 17 日

1 投票

Hello Dear,
I have modified your code. Now it is working as per your requirement.
n_axles = input('define amount of axles');
wheel_parameters = zeros(n_axles,5); %create # vector for # axles
for j = 1:n_axles
parameters1 = input('define load (kg)');
parameters2 = input('define pressure (kpa)');
parameters3 = input('recommended pressure (kpa)');
parameters4 = input('define width (m)');
parameters5 = input('define diameter (m)');
wheel_parameters(j,:) = [parameters1, parameters2, parameters3, parameters4, parameters5]
end
I've removed some unnecessary lines.

1 件のコメント

wswur
wswur 2017 年 5 月 18 日
Thank you very much for helping me out! I guess I was thinking to hard and made it too complicated ;)

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

その他の回答 (1 件)

Matt J
Matt J 2017 年 5 月 17 日
編集済み: Matt J 2017 年 5 月 17 日

0 投票

wheel_parameters(j,:) = [parameters1, parameters2,...]
Also, remove the line
j=j+1
The loop variable j will be incremented automatically.

1 件のコメント

wswur
wswur 2017 年 5 月 18 日
Thanks for helping me out!

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2017 年 5 月 17 日

コメント済み:

2017 年 5 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by