# 3d line plot help

조회 수: 1 (최근 30일)
Robert Tapia 2020년 6월 25일
댓글: Robert Tapia 2020년 6월 25일
T = linspace(-7.5,17,120);
S = linspace(-4.5,28,120);
Y = Piecewise(T,S);
function Yn = Piecewise(X1,X2)
T = linspace(-7.5,17,120);
N = length(T);
for n = 1:N
if X1(n) > 0
Y1(n) = cos(X1(n));
end
if X1(n) <= 0
Y1(n) = exp(X1(n));
end
if X2(n) > 0
Y2(n) = sin(X2(n));
end
if X2(n) <= 0
Y2(n) = 3*X2(n);
end
Yn = Y1(n).*Y2(n)
end
end
need some help so im asked to create a 3d line plot for 2 arrays T and S and then Y which solves a piecewise function, although im getting an error that states "vectors must be the same length " ? is my issue that Y isnt being properly solved ?

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

### 답변 (1개)

Rafael Hernandez-Walls 2020년 6월 25일
Using this function:
function Y = Piecewise(X1,X2)
T = linspace(-7.5,17,120);
N = length(T);
for n = 1:N
if X1(n) > 0
Y1(n) = cos(X1(n));
end
if X1(n) <= 0
Y1(n) = exp(X1(n));
end
if X2(n) > 0
Y2(n) = sin(X2(n));
end
if X2(n) <= 0
Y2(n) = 3*X2(n);
end
Y(n) = Y1(n).*Y2(n);
end
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Robert Tapia 2020년 6월 25일
sorry can you explain a bit the difference from mine and why it would fix the vector length when plotting

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

### 카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by