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

2 ビュー (過去 30 日間)
John Barr 2019 年 12 月 7 日
Edited: Image Analyst 2019 年 12 月 7 日
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,:));

#### 0 件のコメント

サインイン to comment.

### 件の回答 (1)

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.

#### 0 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

Translated by