Importdata does not work anymore in r2018b
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone,
about one year ago I released my MSc thesis for which I had to develop many scripts in order to postprocess data from CFD simulations. Everything worked well at that time. Lately I resumed in hand those scripts for preparing a presentation for a job application I did but each and every script does not work anymore. Everyone of them gives me the same error: Error using importdata Unable to open file.
Every scripts had to import the data of the simulation which were stored in some txt files. The txt files are in some subdirectories located in the directory where the scripts are.
I use a loop with the following instruction to import the txt from every subdir and to load them into a 3D structure (# data * # cells * # subdir):
testfiledir = [ 'C:\Users\user\Desktop\ENRICO\TESI\codice\', file_name ];
addpath(testfiledir);
fileID = [ file_name, '.txt' ];
imp = importdata(fileID);
where filename changes at every iteration of the loop.
Please note that not a single word of the scripts has changed since they were running one year ago. Could be that there were some updates for which importdata does not work anymore with the same inputs?
I Use Matlab r2018b.
I hope that my explanation is sufficiently clear and I will be most thankful t everyone who can help.
P.S: this is the full code, the problem are in section Files upload.
%% Clear
clear all
close all
clc
%% Format
format long;
%% Super loop
for i = 1:20
file_name = [ 'codevof', num2str(i) ]; %choose the desired case to be plotted
switch file_name
case 'codevof1'
MU(i) = 1 / 2800;
RE(i) = 1 / MU(i);
PHI(i) = 5;
case 'codevof2'
MU(i) = 1 / 2800;
RE(i) = 1 / MU(i);
PHI(i) = 10;
case 'codevof3'
MU(i) = 1 / 2800;
RE(i) = 1 / MU(i);
PHI(i) = 20;
case 'codevof4'
MU(i) = 1 / 1400;
RE(i) = 1 / MU(i);
PHI(i) = 5;
case 'codevof5'
MU(i) = 1 / 1400;
RE(i) = 1 / MU(i);
PHI(i) = 10;
case 'codevof6'
MU(i) = 1 / 1400;
RE(i) = 1 / MU(i);
PHI(i) = 20;
case 'codevof7'
MU(i) = 1 / 2100;
RE(i) = 1 / MU(i);
PHI(i) = 5;
case 'codevof8'
MU(i) = 1 / 2100;
RE(i) = 1 / MU(i);
PHI(i) = 10;
case 'codevof9'
MU(i) = 1 / 2100;
RE(i) = 1 / MU(i);
PHI(i) = 20;
case 'codevof10'
MU(i) = 1 / 700;
RE(i) = 1 / MU(i);
PHI(i) = 5;
case 'codevof11'
MU(i) = 1 / 700;
RE(i) = 1 / MU(i);
PHI(i) = 10;
case 'codevof12'
MU(i) = 1 / 700;
RE(i) = 1 / MU(i);
PHI(i) = 20;
case 'codevof13'
MU(i) = 1 / 2800;
RE(i) = 1 / MU(i);
PHI(i) = 15;
case 'codevof14'
MU(i) = 1 / 2100;
RE(i) = 1 / MU(i);
PHI(i) = 15;
case 'codevof15'
MU(i) = 1 / 1400;
RE(i) = 1 / MU(i);
PHI(i) = 15;
case 'codevof16'
MU(i) = 1 / 700;
RE(i) = 1 / MU(i);
PHI(i) = 15;
case 'codevof17'
MU(i) = 1 / 2800;
RE(i) = 1 / MU(i);
PHI(i) = 25;
case 'codevof18'
MU(i) = 1 / 2100;
RE(i) = 1 / MU(i);
PHI(i) = 25;
case 'codevof19'
MU(i) = 1 / 1400;
RE(i) = 1 / MU(i);
PHI(i) = 25;
case 'codevof20'
MU(i) = 1 / 700;
RE(i) = 1 / MU(i);
PHI(i) = 25;
otherwise
disp('ERROR!! Input file not found!')
return
end
rho = 1.0;
%% Files upload
testfiledir = [ 'C:\Users\user\Desktop\ENRICO\TESI\codice\', file_name ];
addpath(testfiledir);
fileID = [ file_name, '.txt' ];
imp = importdata(fileID);
A(:,:,i) = imp.data;
u_tau(i) = sqrt( A(1,17,i) / rho );
j = 1;
while A(j,3,i) <= ( 0.90 * max( A(:,3,i) ) )
DELTA(i) = A(j,3,i);
j = j + 1;
end
DELTA1(i) = MU(i) ./ rho ./ u_tau(i);
Re_tau(i) = u_tau(i) * DELTA(i) * rho / MU(i);
Re_tau1(i) = u_tau(i) .* RE(i);
v_wall(:,i) = A(:,3,i) ./ u_tau(i);
z_wall(:,i) = A(:,1,i) .* u_tau(i) .* rho ./ MU(i);
%% Diagrams
figure(1)
set(gca,'FontSize',15)
txt = ['Re=',num2str(RE(i)),',\Phi=',num2str(PHI(i)),'%'];
semilogx( z_wall(1:end/2,i), v_wall(1:end/2,i),'DisplayName',txt );
title('v+(z+)')
xlabel('z^+')
ylabel('v^+')
%grid on
%grid minor
hold on
legend show
figure(2)
set(gca,'FontSize',15)
txt = ['Re=',num2str(RE(i)),',\Phi=',num2str(PHI(i)),'%'];
plot( A(:,1,i), A(:,6,i),'DisplayName',txt );
title('uu(z)')
xlabel('z')
ylabel('uu')
%grid on
%grid minor
hold on
legend show
figure(3)
set(gca,'FontSize',15)
txt = ['Re=',num2str(RE(i)),',\Phi=',num2str(PHI(i)),'%'];
plot( A(:,1,i), A(:,7,i) - A(:,3,i).^2,'DisplayName',txt );
title('vv(z)')
xlabel('z')
ylabel('vv')
%grid on
%grid minor
hold on
legend show
figure(4)
set(gca,'FontSize',15)
txt = ['Re=',num2str(RE(i)),',\Phi=',num2str(PHI(i)),'%'];
plot( A(:,1,i), A(:,8,i),'DisplayName',txt );
title('ww(z)')
xlabel('z')
ylabel('ww')
%grid on
%grid minor
hold on
legend show
figure(5)
set(gca,'FontSize',15)
txt = ['Re=',num2str(RE(i)),',\Phi=',num2str(PHI(i)),'%'];
plot( A(:,1,i), A(:,12,i),'DisplayName',txt );
title('vw(z)')
xlabel('z')
ylabel('vw')
%grid on
%grid minor
hold on
legend show
figure(6)
set(gca,'FontSize',15)
txt = ['Re=',num2str(RE(i)),',\Phi=',num2str(PHI(i)),'%'];
plot( A(:,1,i), A(:,13,i),'DisplayName',txt );
title('\Phi(z)')
xlabel('z')
ylabel('\Phi')
%grid on
%grid minor
hold on
legend show
end
1 commentaire
dpb
le 15 Déc 2020
Note the error is not that importdata fails to read the file; the problem is that the file cannot be opened.
That means that you probably have changed your file arrangement or default path location or somesuch in the time since you were last working on these files. A lot can happen in a year; one rarely remembers having done things that will have such ramifications.
As Steven L says in his Answer, fix your script to use fullfile and use those properly-built and fully-qualified file names to locate and read the files and all will work again...of course if there are network issues of accessibility or the like because of IT changes or somesuch, you'll have to get those worked out.
Réponses (1)
Steven Lord
le 15 Déc 2020
The obvious questions are:
- Do the files have the same names as they did before?
- Are the files in the same directory as they were before?
- Do you have permissions to read those files in that directory?
Rather than adding a whole bunch of directories to the MATLAB path, you probably want to use fullfile to create fully qualified names and refer to the files in the importdata command using those full names.
0 commentaires
Voir également
Catégories
En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!