Index in position 1 is invalid. Array indices must be positive integers or logical values.

1 次查看(过去 30 天)
Getting the error
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in Untitled (line 35) plot(x, Tdata(0,:));
when running. Cannot figure out how to make the plot work in the following script.
b = 0.0003;
a = 1.5;
d = 5.3;
c = 1.8;
R = 2/100; %m
Tr = -45; %degC
Ti = -30; %degC
N = 10;
x = linspace(-R,R,(2*N+1));
dx = x(2)-x(1);
T = zeros(size(x));
T = T + Ti;
T(1) = Tr;
T(end) = Tr;
Tdata = T;
dt = 1.8;
T1 = T;
T2 = zeros(size(T1));
ndt = 1800/dt;
for j = 1:ndt
T2(1) = Tr;
T2(end) = Tr;
for i=2; length(T2)-1;
T2(i) = T1(i) + dt/2/dx/dx/(c+d*T1(i))*((2*a+b*(T1(i+1)+T1(i)))*(T1(i+1)-T1(i))-(2*a+b*(T1(i-1)+T1(i)))*(T1(i)-T1(i-1)));
end
Tdata = [Tdata;T2];
T1=T2;
end
plot(x, Tdata(0,:));

回答(1 个)

Image Analyst
Image Analyst 2019-12-7
编辑:Image Analyst 2019-12-7
The first row is not 0 -- it's 1. Try
plot(x, Tdata(1,:), 'b-', 'LineWidth', 2);
This is one of the most frequently asked questions, so for a full discussion with solutions, see the FAQ.

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by