Error in plot... vectors must be same length

조회 수: 7 (최근 30일)
Kuhu Singh
Kuhu Singh 2022년 4월 9일
답변: KSSV 2022년 4월 9일
N=30; %no of divisions;
l=30;
delta_x=l/N;
M(1,1)=0;
N(1,1)=1;
O(1,1)=0;
P(1,1)=100;
M(N+1,1)=0;
N(N+1,1)=1;
O(N+1,1)=0;
P(N+1,1)=100;
M(2:N,1)=1;
N(2:N,1)=-(2+0.071^2);
O(2:N,1)=1;
P(2:N,1)=0;
x(1,1)= 100;
x(N+1,1)=100;
%Thomas Algorithm
for p=2:N+1
N(p,1)=N(p,1)-(M(p,1)/N(p-1,1))*O(p-1,1);
P(p,1)=P(p,1)-(M(p,1)/N(p-1,1))*P(p-1,1);
M(p,1)=0;
end
for p=N:-1:2
x(p,1)=(P(p,1)-O(p,1)*x(p+1,1))/N(p,1);
end
plot((0:1:30),x);
grid on;
xlabel("Variation of Length (x) in (cm) ");
ylabel("Temperature in Celsius");
title("Temperature vs Variation of length (TDMA)");
hold on;

답변 (1개)

KSSV
KSSV 2022년 4월 9일
These lines:
N=30; %no of divisions;
l=30;
delta_x=l/N;
M(1,1)=0;
N(1,1)=1; % <---- over writitng values of N
Why you are overwrititng the value of N? You have defined it to 30, but later you over write it to 1. So at the end, your x size is 1x2, you tried plotting it w.r.t. a vector of size 1x30 so error popped out. Modify your code.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by