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

조회 수: 4 (최근 30일)
Hussein Kokash 2023년 1월 12일
답변: Steven Lord 2023년 1월 12일
Hello everyone,
I am trying to execute this code and I am having the following error:
clc;clear;close all
SnapshotsAddress = pwd; % put current path here
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);
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;
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
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 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.

댓글을 달려면 로그인하십시오.

카테고리

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