필터 지우기
필터 지우기

Array indices must be positive integers or logical values.

조회 수: 1 (최근 30일)
matlabgod
matlabgod 2018년 9월 27일
댓글: Star Strider 2018년 9월 27일
I'm trying to create a loop that plots the function for each t value on the same graph, I am getting an "Array indices must be positive integers or logical values." error.
t = [1 24 48 72];
x = linspace(0,1,4);
for ii = length(t)
u=1.656e-5;
c(x)=(0.5).*erfc(x./(2.*sqrt(u.*t)));
plot (x, c)
end

답변 (1개)

Star Strider
Star Strider 2018년 9월 27일
This will run:
t = [1 24 48 72];
x = linspace(0,1,4);
for ii = length(t)
u=1.656e-5;
c(ii)=(0.5).*erfc(x(ii)./(2.*sqrt(u.*t(ii))));
plot (x, c)
end
although you may want to experiment with it.
Note that I subscripted ‘x’ and ‘t’, since I assume that is what you intend.
  댓글 수: 2
matlabgod
matlabgod 2018년 9월 27일
Hi thanks for the quick response, but now I'm getting "Error using plot Vectors must be the same length." error.
Star Strider
Star Strider 2018년 9월 27일
My pleasure.
You must be using different size vectors for ‘t’ and ‘x’.
My code works with the code you posted.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by