a question about plotting

1 回表示 (過去 30 日間)
Johnny
Johnny 2019 年 12 月 8 日
コメント済み: FraFal 2019 年 12 月 8 日
Q.
I have many S seperately with different on lines on the plot, lines with different k have different colours and shapes. I change the coding to make it more efficient, but now I have no idea how to have a same plot of my original one.
1/ my original codes for S and k, and my original plotting codes
I = 1:100
k03 = 0.3
k1 = 1
k3 = 3
k5 = 5
k8 = 8
k13 = 13
k15 = 15
k18 = 18
k23 = 23
k25 = 25
k28 = 28
S03F = k03*log(I)
S1F = k1*log(I)
S3F = k3*log(I)
S5F = k5*log(I)
S8F = k8*log(I)
S13F = k13*log(I)
S15F = k15*log(I)
S18F = k18*log(I)
S23F = k23*log(I)
S25F = k25*log(I)
S28F = k28*log(I)
figure(1)
hold on
plot(S03F,'co-','markersize',3,'Displayname','k<1');
plot(S1F,'gs-','markersize',3,'Displayname','k=1');
plot(S3F,'gs-','markersize',3,'Displayname','k=3');
plot(S5F,'gs-','markersize',3,'Displayname','k=5');
plot(S8F,'gs-','markersize',3,'Displayname','k=8');
plot(S13F,'md-','markersize',3,'Displayname','k=13');
plot(S15F,'md-','markersize',3,'Displayname','k=15');
plot(S18F,'md-','markersize',3,'Displayname','k=15');
plot(S23F,'rp-','markersize',3,'Displayname','k=23');
plot(S25F,'rp-','markersize',3,'Displayname','k=25');
plot(S28F,'rp-','markersize',3,'Displayname','k=28');
title({'Stevens Law:Power Function'...
'\fontsize{9}Relaitionship Between Subjective and Actual Stimulus Magnitude'...
'\fontsize{9}\color{blue} Under Various k Value'});
lgd = legend ('Location','northwest');
lgd.NumColumns = 4;
lgd.FontSize = 6;
hold off
2. the codes now for S and k
I = 1:100;
kV = [0.3;1;3;5;8;13;15;18;23;25;28];
SV = kV.*log(I)

採用された回答

FraFal
FraFal 2019 年 12 月 8 日
Hi,
if you want to mantain your plot design, you can indexing your array. As example:
figure(1); hold on:
plot(SV(1), 'co-','markersize',3,'Displayname','k<1');
plot(SV(2),'gs-','markersize',3,'Displayname','k=1');
...
hold off
BR,
FraFal
  2 件のコメント
Johnny
Johnny 2019 年 12 月 8 日
Thank you for your answer.
Follow is the coding follow your instructions. The result of the graph has no lines but one dot in the middle. Is there anything I did wrong?
hold on
plot(SV(1), 'co-','markersize',3,'Displayname','k=0.3');
plot(SV(2),'gs-','markersize',3,'Displayname','k=1');
plot(SV(3),'gs-','markersize',3,'Displayname','k=3');
plot(SV(4),'gs-','markersize',3,'Displayname','k=5');
plot(SV(5),'gs-','markersize',3,'Displayname','k=8');
plot(SV(6),'md-','markersize',3,'Displayname','k=13');
plot(SV(7),'md-','markersize',3,'Displayname','k=15');
plot(SV(8),'md-','markersize',3,'Displayname','k=18');
plot(SV(9),'rp-','markersize',3,'Displayname','k=23');
plot(SV(10),'rp-','markersize',3,'Displayname','k=25');
plot(SV(11),'rp-','markersize',3,'Displayname','k=28');
title({'Fechner Law:Logarithmic Function'...
'\fontsize{9}\Relaitionship Between Subjective Magnitude and Actual Stimulus Magnitude'...
'\fontsize{9}\color{blue} Under Various k Value'});
xlabel ('Acual Stimulus Magnitude');
ylabel ('Subjective Magnitude');
lgd = legend ('Location','northwest');
lgd.NumColumns = 4;
lgd.FontSize = 6;
hold off
FraFal
FraFal 2019 年 12 月 8 日
yes, sorry. Your output data is a matrix (it's a product-vector between 2 arrays).
In this way, you plot only one point/data of the array. If you want to plot data of each array, you have to define something like that: SV(: , 1) ...or SV(1,:).. depending on how your matrix data was defined. In this way for each row/column, you plot the respective column/row.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by