フィルターのクリア

Exponential Function Plotting From Reverse

1 回表示 (過去 30 日間)
tinkyminky93
tinkyminky93 2022 年 2 月 26 日
コメント済み: Star Strider 2022 年 2 月 26 日
Hello,
I want to plot the graph of exponential function but in reverse order. For example I want this plot to start from 5 and decrease until 0 not from 0 to 5. I will also use drawnow to animate the plot. How can I do that time operation? My code is like that. I want this operation comes reversely.
clear all
close all
t = 0:1:150;
x = log(1004*t);
figure
for i=1:numel(t)
plot(t(i),x(i),'.','Color','r')
hold on
drawnow
ylim([0 30])
xlim([0 150])
grid minor
end

採用された回答

Star Strider
Star Strider 2022 年 2 月 26 日
I initially could not get the 'XDir' to 'reverse' before the loop. Apparently it is necessary to plot something and then set the axes to 'reverse'.
Try this —
t = 150:-1:0;
x = log(1004*t);
figure
Ax = axes;
plot(Ax,NaN,NaN)
Ax.XDir = 'reverse';
hold on
for i=1:numel(t)
plot(Ax,t(i),x(i),'.','Color','r')
drawnow
ylim([0 30])
xlim([0 150])
grid minor
end
The animation will not show here, so run it offlline to see the effect.
.
  2 件のコメント
tinkyminky93
tinkyminky93 2022 年 2 月 26 日
編集済み: tinkyminky93 2022 年 2 月 26 日
The only thing that we should do is setting t= 150:-0.1:0
I solved the problem. When I run your code, it is the same as KSSV's graph.
I don't need to reverse the axes. I just need to reverse the time. :)
Star Strider
Star Strider 2022 年 2 月 26 日
I don't need to reverse the axes. I just need to reverse the time. :)’
That was not obvious from the way the question was stated. (I initially reversed ‘t’, however it took a bit of experimentation to also reverse the x-direction. I wanted to provide a complete solution.)

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

その他の回答 (1 件)

KSSV
KSSV 2022 年 2 月 26 日
編集済み: KSSV 2022 年 2 月 26 日
clear all
close all
t = 0:1:150;
x = log(1004*t);
figure
plot(t,x,'Color','r')
grid minor
set(gca,'XDir','reverse')
  4 件のコメント
KSSV
KSSV 2022 年 2 月 26 日
t = 0:1:150;
x = log(1004*t);
figure
plot(t,x,'Color','r')
grid minor
tinkyminky93
tinkyminky93 2022 年 2 月 26 日
Okey sir, that is not what I want to explain but thanks for your effort.

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

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by