Hello
I would like to ask for advice. I have defined an exp function with exponent U * c.
C varies from -1 to.0. (c = -1: 0.1: -0.1)
I can't draw 10 functions with a separate color and legend.
Would you please help me?
Script:
clear all
D=[0,0]; % D - dráha (m), z anglickeho displacement
FU=[0,0];
x=[0:1:150];
for c = -1:0.1:-0.1 % rozne hodnoty parametra "c"
% for c = -0.01 % rozne hodnoty parametra "c"
% d=0;
fU=0;
% fU = fU+exp(D*c);
% FU = [FU fU];
% d = d+x; % konkretna vzdialenost pre jednu rychlost v case
% D = [D d]; % naplnenie postupnym znizovanim rychlosti
fU=exp(c*x);
FU = [FU fU];
D = [D x];
plot(D,FU,'b:')
axis([0,150,0,1])
grid on
grid minor
% legend(c,'Location','northeast')
hold on
end

 採用された回答

Star Strider
Star Strider 2022 年 2 月 13 日

0 投票

The loop is not necessary. Use vector-matrix multiplication instead.
Try this —
clear all
D=[0,0]; % D - dráha (m), z anglickeho displacement
FU=[0,0];
x=[0:1:150];
c = -1:0.1:-0.1; % rozne hodnoty parametra "c"
% for c = -0.01 % rozne hodnoty parametra "c"
% d=0;
fU=0;
% fU = fU+exp(D*c);
% FU = [FU fU];
% d = d+x; % konkretna vzdialenost pre jednu rychlost v case
% D = [D d]; % naplnenie postupnym znizovanim rychlosti
FU = [FU fU];
D = [D x];
fU=exp(c(:)*D);
plot(D,fU,'b:')
axis([0,150,0,1])
grid on
grid minor
legend(compose('c = %.1f',c), 'Location','northeast')
Make appropriate changes to get the desired result.
.

4 件のコメント

Marek Drliciak
Marek Drliciak 2022 年 2 月 13 日
Yes, thank you very much.
If you have time, please, is it possible to set the line color separately? (color spectrum).
Star Strider
Star Strider 2022 年 2 月 13 日
As always, my pleasure!
To get separate line colours, do not specify them, and let MATLAB define them —
clear all
D=[0,0]; % D - dráha (m), z anglickeho displacement
FU=[0,0];
x=[0:1:150];
c = -1:0.1:-0.1; % rozne hodnoty parametra "c"
fU=0;
FU = [FU fU];
D = [D x];
fU=exp(c(:)*D);
plot(D,fU,':', 'LineWidth',2)
axis([0,150,0,1])
grid on
grid minor
xlim([0 60]) % Optional
legend(compose('c = %.1f',c), 'Location','northeast')
Setting the 'LineWidth' to something other than the default is optional. I did it here to make the lines more visible.
.
Marek Drliciak
Marek Drliciak 2022 年 2 月 13 日
Thank you very very much!!!!
Star Strider
Star Strider 2022 年 2 月 13 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Downloads についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by