(Error using vertcat) Dimensions of arrays being concatenated are not consistent
Show older comments
- XYZ_Internal_Table_FINAL_95mm_tableff=100Hz_95mm_88596.csv
- XYZ_Internal_Table_FINAL_95mm_tableff=100Hz_95mm_88514.csv
- XYZ_Internal_Table_FINAL_95mm_tableff=100Hz_95mm_88516.csv
- XYZ_Internal_Table_FINAL_95mm_tableff=100Hz_95mm_88513.csv
- XYZ_Internal_Table_FINAL_95mm_tableff=100Hz_95mm_88595.csv
- XYZ_Internal_Table_FINAL_95mm_tableff=100Hz_95mm_88512.csv
- XYZ_Internal_Table_FINAL_95mm_tableff=100Hz_95mm_88517.csv
- XYZ_Internal_Table_FINAL_95mm_tableff=100Hz_95mm_88515.csv
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))'];
Answers (1)
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 Comments
Kumaresh Kumaresh
on 20 Jun 2025
Walter Roberson
on 20 Jun 2025
If you need to have a 1 x 500 followed by a 1 x 500 followed by a 1 x 8 and then another 1 x 8, then you will need to use a cell array.
Perhaps you want
[x.'; y.'; phix(:,a); phiy(:,a)]
which would be [500 x 1; 500 x 1; 8 x 1; 8 x 1] giving 1016 x 1 overall.
Kumaresh Kumaresh
on 20 Jun 2025
Kumaresh Kumaresh
on 20 Jun 2025
Edited: Kumaresh Kumaresh
on 20 Jun 2025
The Ux you get from the command
%SVD on X1
[Ux, Sx, Vx] = svd(X1,'econ');
is a 8x8 matrix for your first .csv-file. Thus for r > 8, the command
Ux = Ux(:,1:r);
references columns in Ux that do not exist.
The other warnings tell you that you try to find inverses of matrices that are numerically singular (i.e. for which numerically a senseful inverse cannot be computed).
Example:
A = [1 0;0 1e-65];
B = [1 2;3 4];
B/A
Kumaresh Kumaresh
on 20 Jun 2025
Edited: Kumaresh Kumaresh
on 20 Jun 2025
Torsten
on 20 Jun 2025
The number of rows of Ux is 20, but the number of columns of Ux is 10. Thus still r <= 10 is required.
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!