(Error using vertcat) Dimensions of arrays being concatenated are not consistent

2 ビュー (過去 30 日間)
Kumaresh Kumaresh
Kumaresh Kumaresh 2025 年 6 月 19 日
コメント済み: Torsten 2025 年 6 月 20 日
Hello all,
Here is my code. Some related .csv files are attached.
After running the code, I face this error:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in Code_Yahya (line 105)
phia =[x;y;phix(:,a)';phiy(:,a)'];
>> both phix and phiy are of same sizes.
Can someone help me here ?
Thank you
%%% Tables are exported as vertices from STARCCM+
%%% ------------------------------------------------------------------%%%
clear; clc; close all;
f=dir('*.csv'); % finding all csv files
n_snapshots=size(f,1); % finding number of snapshots
for i=1:n_snapshots
fn=f(i).name; % Listing filenames
fid=fopen(fn, 'r'); % reading files
data = fscanf(fid, '%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f' , [11, inf]);
% exporting columns
x=data(9,:);
y=data(10,:);
%Ut(:,i) = data(:,1);
u(:,i) = data(:,3);
v(:,i) = data(:,2);
fclose(fid);
end
%--------------------------------------------------------------
u = permute(u,[2 1]);
%Split u into two snapshot sets
X1 = u(:,1:end-1);
X2 = u(:,2:end);
%SVD on X1
[Ux, Sx, Vx] = svd(X1,'econ');
%Compute DMD (phix are Eigen vectors)
r = 3; %truncate as 10 modes
%Reduce rank
Ux = Ux(:,1:r);
Sx = Sx(1:r,1:r);
Vx = Vx(:,1:r);
%Gets A_tilde
A_tildex = Ux'*X2*Vx/Sx;
%Compute A_tilde eigenvalues and eigenvectors
%[eVecs, Eigenvalues] = eig(A_tilde);
[Wx, eigsx] = eig(A_tildex);
%DMD modes
phix = X2*Vx/Sx*Wx; %Eigenvectors
figure
theta = (0:1:100)*2*pi/100;
plot(cos(theta),sin(theta),'k--') % plot unit circle
hold on, grid on
scatter(real(max(eigsx)),imag(max(eigsx)),'ok')
axis([-1.1 1.1 -1.1 1.1]);
%--------------------------------------------------------------
v = permute(v,[2 1]);
%Split u into two snapshot sets
Y1 = v(:,1:end-1);
Y2 = v(:,2:end);
%SVD on X1
[Uy, Sy, Vy] = svd(Y1,'econ');
%Compute DMD (phix are Eigen vectors)
r = 3; %truncate as 10 modes
%Reduce rank
Uy = Uy(:,1:r);
Sy = Sy(1:r,1:r);
Vy = Vy(:,1:r);
%Gets A_tilde
A_tildey = Uy'*Y2*Vy/Sy;
%Compute A_tilde eigenvalues and eigenvectors
%[eVecs, Eigenvalues] = eig(A_tilde);
[Wy, eigsy] = eig(A_tildey);
%DMD modes
phiy = Y2*Vy/Sy*Wy; %Eigenvectors
figure
theta = (0:1:100)*2*pi/100;
plot(cos(theta),sin(theta),'k--') % plot unit circle
hold on, grid on
scatter(real(max(eigsy)),imag(max(eigsy)),'ok')
axis([-1.1 1.1 -1.1 1.1]);
%--------------------------------------------------------------
Gridnumber = size(x, 2);
for j=1:r %n_snapshots
phinor = 0;
for i=1:r %Gridnumber
phinor = phinor + power(phix(i,j),2) + power(phiy(i,j),2);
%phinor = phinor + power(phix(i,j),2);
end
phinor = sqrt(phinor);
phix(:, j) = phix(:, j) / phinor;
phiy(:, j) = phiy(:, j) / phinor;
end
%Extracting modes
for a=1:r %n_snapshots
FilNamPhi=1000+a; %FilNamPhi=1000+a;
PhiOut = fopen([num2str(FilNamPhi), '.txt'], 'wt');
fprintf(PhiOut,'');
phia =[x;y;phix(:,a)';phiy(:,a)'];
fprintf(PhiOut, '%20.9f %20.9f %20.9f %20.9f\n',phia);
fclose(PhiOut);
end
%xlswrite('eigenvaluesX.xlsx',[real(max(eigsx))',imag(max(eigsx))'];
%xlswrite('eigenvaluesY.xlsx',[real(max(eigsy))',imag(max(eigsy))'];

回答 (1 件)

Torsten
Torsten 2025 年 6 月 19 日
移動済み: Torsten 2025 年 6 月 19 日
x and y are of size 1x500, phix(:,a)' and phiy(:,a)' are of size 1x8. So either x and y had to be of size 1x8 or phix(:,a)' and phiy(:,a)' had to be of size 1x500 for that phia =[x;y;phix(:,a)';phiy(:,a)']; would make sense.
  7 件のコメント
Kumaresh Kumaresh
Kumaresh Kumaresh 2025 年 6 月 20 日
編集済み: Kumaresh Kumaresh 2025 年 6 月 20 日
Torsten
Torsten 2025 年 6 月 20 日
The number of rows of Ux is 20, but the number of columns of Ux is 10. Thus still r <= 10 is required.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by