How to add values to an array using a while loop

50 ビュー (過去 30 日間)
laura byrne
laura byrne 2021 年 3 月 5 日
編集済み: Nagasai Bharat 2021 年 3 月 8 日
How do you add values from a while loop to an empty array? I've tried adding it into the loop, I've tried appending it but nothing seems to work the empty array only outputs one value at the end of the loop.
theta_max_a = zeros(1,6);
while wave_min <= wave_max
theta_max = asind(((m*wave_min)*sf1));
theta_min = asind(((m*wave_min)*sf7));
wave_min = wave_min + 50e-09;
end
theta_max_a
  1 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 3 月 5 日
You have not assigned any value to "theta_max_a" other than pre-allocation.

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

回答 (1 件)

Nagasai Bharat
Nagasai Bharat 2021 年 3 月 8 日
編集済み: Nagasai Bharat 2021 年 3 月 8 日
Hi,
From my understanding you are trying to add values into an array after each iteration of a loop. The following example code would help you understand the task.
empty_array = zeros(1,6);
for i=1:10
empty_array = [empty_array , 1];
end
empty_array
This would increase the array size to 1, 16.

カテゴリ

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