Azzera filtri
Azzera filtri

Error: "filename" must be a string scalar or character vector.

68 visualizzazioni (ultimi 30 giorni)
I am trying to sort of creat an animation of a bunch of text files. The thing is, these text files are techically 3D matrices collapsed as 2D matrix and then I am reshaping them back to 3D to plot.
The code:
upperDir = 'C:\Users\J\Desktop\Folder\';
subDir = {'DataFile\'};
Frame = 161; %number of text files
Nx = 64;
Ny =64;
Nz = 64;
Lx =128;
Ly = 128;
Lz = 128;
x = (0:Nx-1)/Nx*2*pi;
y = (0:Ny-1)/Ny*2*pi;
z = (0:Nz-1)/Nz*2*pi;
dx = Lx/Nx;
dy = Ly/Ny;
dz = Lz/Nz;
[X,Y,Z] = meshgrid(x,y,z);
for i = 1:Frame
%Test=reshape(readmatrix('Test161.txt'),64,64,64);
Test = reshape(readmatrix([upperDir subDir 'n' num2str(i) '.txt']),64,64,64); %error here
figure
isosurface(X,Y,Z,Test);
shading flat;
grid on;
xlabel('x(m)'); ylabel('y(m)'); zlabel('z(m)');
end
The error:
Error using readmatrix (line 157)
"filename" must be a string scalar or character vector.
Error in PlasmaCloud3DFourier (line 351)
Test = reshape(readmatrix([upperDir subDir 'n' num2str(i) '.txt']),64,64,64);

Risposte (2)

KSSV
KSSV il 26 Ott 2022
Change this line
[upperDir subDir 'n' num2str(i) '.txt']
to
[upperDir,filesep,subDir,filesep,'n',num2str(i),'.txt']
Also have a look on dir. Here you can extract the required text files and make your required path using fullfile
  1 Commento
Jamie Al
Jamie Al il 26 Ott 2022
Modificato: Jamie Al il 26 Ott 2022
Sorry, what is filesep here?. Unfortunately, I am getting the same error.

Accedi per commentare.


VBBV
VBBV il 5 Nov 2022
subDir = 'DataFile\';
Change this line as above.

Categorie

Scopri di più su Dialog Boxes in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by