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

1 回表示 (過去 30 日間)
John Barr
John Barr 2019 年 12 月 7 日
編集済み: 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,:));

回答 (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 Center および File ExchangeMultirate Signal Processing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by