Dot indexing is not supported for variables of this type in a for loop

4 次查看(过去 30 天)
Hello everyone,
I am trying to execute this code and I am having the following error:
clc;clear;close all
addpath('/media/hf9098/easystore/MATLAB/POD')
SnapshotsAddress = pwd; % put current path here
files = dir(fullfile(SnapshotsAddress,'data_*.txt'));
n_snapshots = natsortfiles(files);
if iscell(n_snapshots) == 0;
n_snapshots = (n_snapshots);
end
n_snapshots = size(files,1);
for j = 1:numel(n_snapshots)
folder = n_snapshots(j).folder;
filename = n_snapshots(j).name;
fid = fullfile(n_snapshots(j).folder,n_snapshots(j).name);
data = dlmread(fid);
x = data(1,:) % x coordinate
y = data(2,:) % y coordinate
U(j,:) = data(4,:); % u velocity
V(j,:) = data(5,:); % v velocity
end
%Section 2 -­‐ Compute spatial correlation matrix C
c1 = U*U';
c2 = V*V';
C = (c1+c2)/n_snapshots;
%Section 3 -­‐ Solve the eigenvalue problem: C * EigenVector = EigenValue * EigenVector
[beta, lmd] = svd(C);
%Section 4 -­‐ Calculate basis functions
phix = U'*beta;
phiy = V'*beta;
% Normalize basis functions
GridNum = size(x,2);
for j=1:n_snapshots
PhiNor = 0;
for i=1:GridNum
PhiNor = PhiNor + phix(i,j)^2 + phiy(i,j)^2;
end
PhiNor = sqrt(PhiNor);
phix(:,j)= phix(:,j)/PhiNor;
phiy(:,j)= phiy(:,j)/PhiNor;
end
%Section 5 -­‐ Calculate coefficient
TimCoeU = U*phix;
TimCoeV = V*phiy;
TimCoe = TimCoeU + TimCoeV;
%Section 6 -­‐ Export basis functions
for a=1:n_snapshots
FilNamPhi = 1000+a;
PhiOut = fopen([SnapshotsAddress,num2str(FilNamPhi),'.txt']', 'wt');
fprintf(PhiOut, '#DaVis 7.2.2 2D-­‐vector 16 145 145 "position" "mm" "position" "mm" "velocity" "m/s"\n');
phia = [x;y;phix(:,a)';phiy(:,a)'];
fprintf(PhiOut, '%20.9f %20.9f %20.9f %20.9f\n',phia);
fclose(PhiOut);
end
% Write coefficients into excel file
xlswrite([SnapshotsAddress,'TimCoe.xlsx'],TimCoe);
The error is:
Dot indexing is not supported for variables of this type.
Error in VelocityDistributionPOD (line 57)
folder = n_snapshots(j).folder;
Even upon commenting line57, it is still present in line58 and line59
Any thoughts how to override such error?
Thank you!

采纳的回答

Steven Lord
Steven Lord 2023-1-12
First:
n_snapshots = natsortfiles(files);
n_snapshots was a struct array. But then:
if iscell(n_snapshots) == 0;
n_snapshots = (n_snapshots);
end
n_snapshots = size(files,1);
you changed it to a scalar double. Change one of the variable names to something more indicative of its purpose.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by