how do i plot a graph after a for loop

so for my assignment i have to plot a graph for deflection angle by angle of attack, however the values for the deflection angle have been calculated using a for loop cycle. how do i plot the results as a single graph?

3 件のコメント

Dyuman Joshi
Dyuman Joshi 2023 年 10 月 25 日
編集済み: Dyuman Joshi 2023 年 10 月 25 日
Store the values in an array and then plot the array.
Depending upon the operations performed in the for loop, you migth be able to vectorize your code as well.
denzel sibanda
denzel sibanda 2023 年 10 月 25 日
how can i store it in an array?
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 25 日
%% Example
for k=1:number_of_iterations
%do some calculations
%store the value
deflection_angle(k) = value_from_calculation;
end
If the size of the final output is known, consider Preallocation.
Also, I recommend you start with the free MATLAB Onramp tutorial to learn the essentials of MATLAB.

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

回答 (2 件)

Torsten
Torsten 2023 年 10 月 25 日
移動済み: Torsten 2023 年 10 月 25 日

0 投票

Save the deflection angles in an array and plot after the for-loop.
Star Strider
Star Strider 2023 年 10 月 25 日

0 投票

Subscript the variables-of-interest in the loop according to the loop index counter values, and then plot those variables after the loop terminates. They should be vectors and should plot correctly.
Example —
for k = 1:10
x(k) = cos(k);
y(k) = sin(k);
end
figure
plot(x, y)
grid
.

カテゴリ

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

製品

リリース

R2023b

タグ

質問済み:

2023 年 10 月 25 日

コメント済み:

2023 年 10 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by