How can I vectorize this plot?

3 ビュー (過去 30 日間)
David Meixell
David Meixell 2020 年 9 月 29 日
コメント済み: madhan ravi 2020 年 9 月 29 日
It would be pretty easy to use a For loop here, but the requirement is the answer be vectorized, avoiding the use of a loop. I'm having issues getting f(x) to plot each iteration of the changing intervals for 'x.' Currently, I'm only getting it to plot the first iteration with x = [-1: .2 : 1]. How can I get each value of 'n' to be inserted to 'x' and plot the resultant 'f'?
n = [.2 .1 .01]; % Interval steps to cycle through for each plot
x = [-1 : n : 1]; % Range of values with interval 'n'
f = x .* sin((pi * (1 + 20 .* x)) / 2);
hold on
plot(x,f)

回答 (1 件)

madhan ravi
madhan ravi 2020 年 9 月 29 日
Not possible without a loop.
  1 件のコメント
madhan ravi
madhan ravi 2020 年 9 月 29 日
arrayfun() or cellfun() is just an implicit loop by the way.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by