Hello, every one
I need graph contain all values of [a,b,c,d] of ...trapezoid function(which is in the picture)...
I tried the ready function which defined in matlab
in the attach file...
but this not plot all the [a,b,c,d], plot only one case...
please...is possible to plot all [a,b,c,d], in the same graph with different colors as possible if can in matlab??..
If any Prof. can help me...thanks alots

2 件のコメント

dpb
dpb 2021 年 6 月 9 日
Can't even begin to read the image so didn't try...but you can plot as many lines on a given axes as you wish. See
hold on
and examples in graphics documentation for plot
hasan s
hasan s 2021 年 6 月 9 日
thanks prof. for your reply
I tried hold on in 2 or 3 axes as points, but I dont know how used hold on to this like[a,b,c,d] contain lines ,as trapezoid

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

 採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 9 日

0 投票

format long
m=100;
v1=unifrnd(0,1,1,m);
l1=unifrnd(0,1,1,m);
u1=unifrnd(1,2,1,m);
a = 0.1*l1';
b = 2*v1';
c = 3*v1';
d = 4*u1';
x = 0:0.1:10;
part0 = 0 .* (x<=a | x >= d);
part1 = 1 .* (x>b & x < c);
part2 = (x-a)./(b-a) .* (x > a & x <= b);
part3 = (d-x)./(d-c) .* (x > b & x <= d);
f = part0 + part1 + part2 + part3;
plot(x, f); ylim([-0.1 1.1*max(f(:))])
The reason this does not look like you expect is that your equations do not define a trapazoid shape: your second and fourth conditions overlap. The change to the fix the equations would be easy. I programmed based upon the definition of f(x), not based upon the guidance that you were expecting a trapazoid.

9 件のコメント

hasan s
hasan s 2021 年 6 月 9 日
編集済み: hasan s 2021 年 6 月 9 日
thanks a lot prof. walter ....great programming
I try it now
Walter Roberson
Walter Roberson 2021 年 6 月 9 日
Pay attention to part3: that is the part you need to fix your equation for.
hasan s
hasan s 2021 年 6 月 10 日
編集済み: hasan s 2021 年 6 月 11 日
Really valuable note,
Thank you very very much prof.Walter.
hasan s
hasan s 2021 年 8 月 11 日
I'm sorry for bothering you...prof. walter
If I may ask...
I used this same yours programming to draw several functions of this pattern in one drawing, but the drawing did not appear for me...the result is
Edges: [0×1 table]
Nodes: [0×0 table]
Knowing that it was also used after the first drawing command, (hold on ) and also the drawing did not appear
I searched a lot and didn't find the answer...
Walter Roberson
Walter Roberson 2021 年 8 月 11 日
Edges and Nodes would normally only show up if you had used a graph() object instead of using plot()
hasan s
hasan s 2021 年 8 月 11 日
編集済み: hasan s 2021 年 8 月 11 日
That's right, thank you very very much for your great answer..
thanks alot prof. walter
But the functions did not appear separately I could not distinguish each function, because of the many colors
hasan s
hasan s 2021 年 8 月 11 日
Is it possible to ask another question, is it possible to choose a different color for each function?
Walter Roberson
Walter Roberson 2021 年 8 月 11 日
format long
m=100;
v1=unifrnd(0,1,1,m);
l1=unifrnd(0,1,1,m);
u1=unifrnd(1,2,1,m);
a = 0.1*l1';
b = 2*v1';
c = 3*v1';
d = 4*u1';
x = 0:0.1:10;
part0 = 0 .* (x<=a | x >= d);
part1 = 1 .* (x>b & x < c);
part2 = (x-a)./(b-a) .* (x > a & x <= b);
part3 = (d-x)./(d-c) .* (x > b & x <= d);
f = part0 + part1 + part2 + part3;
plothandles = plot(x, f); ylim([-0.1 1.1*max(f(:))])
cmap = parula(m);
for K = 1 : m
plothandles(K).Color = cmap(K,:);
end
Each line is colored according to its position in the colormap, cmap, that you create.
Of course with 100 lines, it is going to be difficult to tell them apart anyhow...
hasan s
hasan s 2021 年 8 月 11 日
編集済み: hasan s 2021 年 8 月 14 日
Excellent programming
thanks alot prof. Walter for your help

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

2021 年 6 月 8 日

編集済み:

2021 年 8 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by