Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

plot 2 graphic but continous

Status
Not open for further replies.

ibnuz

Mechanical
Sep 1, 2003
3
i need someone's help n i have a question

How to plot two or more functions but they are cointinous.
the functions maybe like:

y1=2*x for 0<x<2
y2=4 for 2<x<4
y3=2 for x>4

how to plot them in a cartesian coordinate, together.
following illustration is what i want to plot!!

_____
/
/ _______
/
/

how i can do that with standar ploting matlab command...?
(x and y are symbolic expression)
please help me! thank's a lot.
 
Replies continue below

Recommended for you

try something like this (it is very straight forward),

x=0:.1:10;
plot(x,yourfunctionname(x));

function [ y ] = yfunc( x )
%YFUNC Summary of this function goes here
% Detailed explanation goes here
for i=1:size(x,1)
if x(i,1) > 0 & x(i,1) <= 2
y(i,1)=2*x(i,1);
elseif x(i,1)>2 & x(i,1)<4
y(i,1)=4;
elseif x(i,1)>4
y(i,1)=2;
else
y(i,1)=NaN;
end
end
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor