plotting in matlab what should i do?

I want to plot x vs w, from the following code, but I'm not getting the correct plot. Could you explain it for me??
function[x]=packegingsystems(w,k1,k2,d)
if w<(k1*d)
x=w/k1;
else
x=(w+2*k2*d)/(k1+2*k2);
end
display(x)
and my attempt to plotting it:
w=linspace(0,3000,300)
x=packegingsystems(w,1e4,1.5e4,0.1)
plot(w,x)
This is not correct, the plot should consist of two ranges; as defined in the function file.

댓글 수: 3

Image Analyst
Image Analyst 2015년 5월 6일
I fixed your formatting for you this time, but please read this for next time: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
B
B 2015년 5월 6일
thanks!!! I will use next time (Y)
Image Analyst
Image Analyst 2015년 5월 6일
Did you also see my answer below?

답변 (1개)

Image Analyst
Image Analyst 2015년 5월 6일

0 개 추천

Try this:
function x = packegingsystems(w,k1,k2,d)
x=(w+2*k2*d)/(k1+2*k2);
indexes = w < (k1*d); % Logical index.
x(indexes) = w(indexes) / k1;

이 질문은 마감되었습니다.

태그

질문:

B
B
2015년 5월 6일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by