Error using vertcat; Dimensions of arrays being concatenated are not consistent.

1 Ansicht (letzte 30 Tage)
I have this kind of error at line 64. The last plot. Someone could help me to fix it?
clc; clear all; close all;
% parametri inziali
N=30;
L=1;
x=linspace(0,L,N+1);
h=x(2)-x(1);
dx=x(2)-x(1);
% condizione iniziale
phi0=sin(2*pi*x./L);
% parametri
k=1;
b=5;
beta=1.5;
dt=(beta*h*h)/k;
Nt=100;
Tf=Nt*dt;
t=linspace(0,Tf,Nt+1);
% plot([x,L],[phi0,phi0(1)]);
% costruisco i pesi
i=1;
xc=x(i);
wdd=PesiDer(x(1:4),xc,2);
w=PesiDer(x(1:4),xc,0);
switch i
case 1
v2=zeros(1,N);
v2(1)=wdd(1); v2(2)=wdd(2); v3(3)=wdd(3); v2(4)=wdd(4);
case 2
v2=zeros(1,N);
v2(1)=wdd(2); v2(2)=wdd(3); v3(3)=wdd(4); v2(end)=wdd(1);
case 3
v2=zeros(1,N);
v2(1)=wdd(3); v2(2)=wdd(4); v3(end-1)=wdd(1); v2(end)=wdd(2);
case 4
v2=zeros(1,N);
v2(1)=wdd(4); v2(end-2)=wdd(); v3(end-1)=wdd(2); v2(end)=wdd(3);
end
% matrice spaziale
v=zeros(1,N);
v(1)=1;
I=gallery('circul',v);
A=-k*gallery('circul',N,v2)+beta*gallery('circul',N,v);
% matrice temporale
dt=(beta*h*h)/k;
Nt=100;
Tf=Nt*dt;
B=I-.5*A*dt;
C=I+.5*A*dt;
T=B\C;
phi=phi0(1:end-1)';
% soluzione analitica
phia=zeros(Nt,N);
for ite=1:Nt
for isp=1:N
phia=exp((-(b+k)*(2*pi/L)^2)*t(ite))*sin(x(isp));
end
end
for it=2:Nt+1
phin=T*phi; %soluzione numerica
plot([x;x(end)+dx],[phi0;phi0(1)],'.-r',[x;x(end)+dx],[phi;phi(1)],'g',[x;x(end)+dx],[phia(it,:);phia(it,1)],'y');
end
  3 Kommentare
Adam
Adam am 23 Jul. 2018
Just use
doc size
on the command line with a breakpoint at the line in question and you will instantly see the size of the two things you are attempting to concatenate, e.g.
size( phia(it,:) )
Guillaume
Guillaume am 23 Jul. 2018
I've formatted the code for you. It would be useful if you told us which is line 64.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Guillaume
Guillaume am 23 Jul. 2018
What is the intent of
[phia(it,:);phia(it,1)]
in your plot line.
phia(it, :) implies that phia has more than one column since it asks for all columns of row it. phia(it, 1) has of course only one column. Therefore vertically concatenating something with more than one column with something with only one column is always going to fail.
The only way the above can work is if phia has only one column, i.e. is a vector, in which case 2d indexing is misleading and the above could be simply written as
[phia(it); phia(it)] %not likely to be what you meant.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by