필터 지우기
필터 지우기

How to show only parts of a function in a plot, in order to combine functions?

조회 수: 8 (최근 30일)
Hi everyone,
I need some help with this. I got three functions, but I want to plot only part of them and stich them together. This is the code and the figure. So I want the blue line to go up to the intersection with the red line (1,0101,1,0203) and I want the other two plots to not show in this region. Then, from that intersection point, I want the red line to go up to the intersection (5,4545, 3,5692) while omiting the other functions in this interval and thirdly, after this interaction, I want the graph to show only the black line. Is that possible?
x=linspace(0,20)
y=x.^4.*exp(-x);
plot(x,y,'k')
grid on
hold on
y=x.^(3/4);
plot(x,y,'r')
axis([ 0 20 10^(-2) 10^2])
hold on
y=x.^2;
plot(x,y,'b')
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
  댓글 수: 3
Maxtron Moon
Maxtron Moon 2020년 6월 30일
It would look something like this (you know the units and curves are not the same) but basically I want to combine it in this way; the first interval would consist of the blue line, the second of the red and the last of the black line all stiched together to look like a single function)

댓글을 달려면 로그인하십시오.

채택된 답변

Kevin Joshi
Kevin Joshi 2020년 6월 30일
clc;
clear all;
%%
x=linspace(0,20);
y1=x.^4.*exp(-x);
y2=x.^(3/4);
y3=x.^2;
%%
x=linspace(0,20);
[x12,y12] = intersections(x,y1,x,y2,1)
[x23,y23] = intersections(x,y2,x,y3,1)
x3_3 = 0:0.0001:x23(2);
y3_3 = x3_3.^2;
p1 = plot(x3_3,y3_3,'b','LineWidth',1);
hold on
x2_2 = x23(2):0.0001:x12(3);
y2_2 = x2_2.^(3/4);
p2 = plot(x2_2,y2_2,'r','LineWidth',1);
x3_3 = x12(3):0.0001:20;
y3_3 = x3_3.^4.*exp(-x3_3);
p3 = plot(x3_3,y3_3,'k','LineWidth',1);
datatip(p3,x2_2(end),y2_2(end))
axis([10^-2 20 10^(-2) 10^2])
grid on;
set(gca, 'YScale', 'log')
set(gca, 'XScale', 'log')
I have used
to find line intersections.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by