I get an error at the importdata line saying
"Error using importdata (line 137)
Unable to open file."
when I write in 'specimenAl.dat' manually into the function, the program runs fine. How can I make use of the importarray function while defining the argument as an element of an array?
material = {('specimenAl.dat'), ('specimenSt.dat')};
A = importdata(material(1));
Data = A.data;
Force = Data (:,2);
Displacement = Data (:,1);
Strain = Data (:,3);
I had the same problem. fixed it by using {} in
A = importdata(material{1});
Hope this helps!
Related
I am taking a previously generated .h5 file which is 3D and taking a 2D slice. The new 2D h5 file looks complete and as expected, however I then pass this into some modeling software (GPRMax) and get the error KeyError: "Unable to open object (object 'data' doesn't exist)". Previous 2D and 3D .h5 files have been fine, so im not sure whats different. Below is the code used to generate the .h5 file. Any help is appreciated.
hf = h5py.File(dir_path+'\ModelMC0105\ModelA3d1_15102020_170900005701.h5', 'r')
dset = hf['data']
if os.path.exists(dir_path+'\ModelMC0105\ModelA3d1_15102020_170900005701-slice.h5'):
os.remove(dir_path+'\ModelMC0105\ModelA3d1_15102020_170900005701-slice.h5')
hf2 = h5py.File(dir_path+'\ModelMC0105\ModelA3d1_15102020_170900005701-slice.h5','w')
dz_dy_dz = (0.001,0.001,0.001)
hf2.attrs['dx_dy_dz'] = dz_dy_dz
data = hf2.create_dataset("data", (100,1,100))
for i in range(100):
data[i]=(dset[i,50,:])
data=data.ref
print(data)
hf2.close()
hf.close()
Try absolute path, please. It may works.
Here is an example that creates a ['data'] dataset in an HDF5 file, closes, then reopens (read-only) and copies the data in slices to a second HDF5 file. Maybe you will find something to help you.
with h5py.File('SO_64758047.h5','w') as h5w:
arr = np.random.random(100*480*640).reshape(100,480,640)
ds = h5w.create_dataset('data', data=arr)
with h5py.File('SO_64758047.h5','r') as h5r:
dset = h5r['data']
with h5py.File('SO_64758047_2.h5','w') as h5w2:
dz_dy_dz = (0.001,0.001,0.001)
h5w2.attrs['dx_dy_dz'] = dz_dy_dz
data = h5w2.create_dataset('data',(100,480,640))
for i in range(h5r['data'].shape[0]):
print('get slice#',str(i))
data[i] = h5r['data'][i,:,:]
I have a Matlab script where I produce a figure, and then create an eps file in my current directory using the command
print('myFile','-depsc'). Immediately following, I have: mypdf = eps2pdf('myFile').
I get the error message that 'Error while creating temporary eps file: ..... cannot be accessed or does not exist'.
Has anyone had a similar problem? Any suggestions what I might be doing wrong? I'm using Ubuntu and Matlab 2017a.
Here is an example code that I type into the command line. I get the error message which I stated above.
figure()
plot(linspace(1,100),linspace(1,100)) %Simple line
print('my_plot','-depsc') %Create eps file.
mypdf = eps2pdf('my_plot'); %Should produce mypdf in my current directory.
<error message prints>
This isn't a standard function. If you read the function you will see errStr that it returns for this.
function [ok,errStr] = read_epsfilecontent( epsFile )
% Reads the content of the eps file into epsFileContent
global epsFileContent
ok = 0;
errStr = [];
fh = fopen(epsFile,'r');
if fh == -1
errStr = ['File: ' epsFile ' cannot be accessed or does not exist'];
return
end
Then we figure out when fopen returns -1
fileID = fopen(filename) opens the file, filename, for binary read
access, and returns an integer file identifier equal to or greater
than 3. MATLABĀ® reserves file identifiers 0, 1, and 2 for standard
input, standard output (the screen), and standard error, respectively.
If fopen cannot open the file, then fileID is -1.
Which means please post some of your code so we can figure out why it cannot open your file.
Edit: After some work around and it wasn't necessary to download the code this is how I solved your problem. There is another implementation called eps2xxx
While running your code I received this error
Error while creating temporary eps file: *.eps - File:
C:\Users\Ryan\Documents\MATLAB*.eps cannot be accessed or does not
exist
Which lead me to the information in the documentation here.
% Create tmp file,...
[ok,errStr] = create_tmpepsfile(source,tmpFile,orientation);
if ~ok
status = ['Error while creating temporary eps file: ' epsFile ' - ' errStr];
if nargout, result = 1; end;
if nargout > 1, msg = status; else, disp(status); end;
And I read you needed GhostScript, I wasn't sure if I had this anyways. I downloaded it and gave the full pathway to GS like the following.
figure()
fullgspath = 'C:\Program Files\gs\gs9.23\bin\gswin64c.exe';
plot(linspace(1,100),linspace(1,100)); %Simple line
print('my_plot','-depsc');
eps2xxx('my_plot.eps',{'pdf'},fullgspath);
which created your nice little pdf here.
The pngwritec function is at the core of my program, but however, I get a series of errors when I run my main file.
Error using pngwritec
PNG library failed: Write Error.
There does not seem to be any documentation available online, yet somehow, when I ran the same program a couple of days ago, there was no issue. Is this a side effect of some new Matlab update? I'm using Matlab 2017b.
Edit:
The error shows up at the first time I need to convert an image to PNG using imwrite.
if (~exist(fullfile(denoiseFolder, [nameF '_d' extF]), 'file') | overwrite)
if saveWaveletCoeffs
waveletFileName = fullfile(saveWaveletFolder, [nameF '_w.mat']);
else
waveletFileName = '';
end
imIn = imread(fileName);
imOut = waveletDenoise(imIn, sigma0, waveletFileName);
imOut = uint8(round(imOut));
fileName = fullfile(denoiseFolder, [nameF '_d' extF]);
imwrite(imOut, fileName, 'png'); %Error here
end
The following code is used to read and label data from an eeg file.
Matlab gives the following error:
Error using sscanf
First argument must be a string.
Is there a way to fix this?
%% File Names reading and label generation
dataFolder= 'SMNI_CMI_TRAIN/';
fileNames = dir([dataFolder 'c*.*']);
lbl = sscanf(cat(1,fileNames.name)','co2%c%d.rd.%d');
status = lbl(1:3:end);
id = lbl(2:3:end);
ids = unique(id);
trial = lbl(3:3:end);
I am using a script which generate a collection of strings in a loop:
'folder1/im1'
'folder1/im2'
...
'folder1/im3'
I assign the string to a variable, when I try to execute the img = dicomread(file); function I get the following error:
Error using dicomread>newDicomread (line 164)
The first input argument must be a filename or DICOM info struct.
Error in dicomread (line 80)
[X, map, alpha, overlays] = newDicomread(msgname, frames);
Error in time (line 14)
img = dicomread(file);
However, using the command line I don't get errors: img = dicomread('folder1/im1').
The code is the next:
for i=1:6 %six cases
nameDir = strcat('folder', int2str(i));
dirData = dir(nameDir);
dirIndex = [dirData.isdir];
fileList = {dirData(~dirIndex).name}; % list of files for each directory
n = size(fileList);
cd(nameDir);
for x = 1:n(2)
img = dicomread(strcat(pwd(), '/', fileList(x)));
end
cd('..');
end
What could be the error?
You've figured it out by now, haven't you.
Based on what you've written, you test
img = dicomread('folder1/im1');
when what you are having trouble with is
img = dicomread(file);
You need to actually test the line you are having trouble with. I would recommend:
putting a break point in test.m a the line img = dicomread(file). When you get to that line you can see what file is equal to. Also do whos file to make sure it is of class char and not a cell array or something random.
If you still want help, edit your original post and show the code where you assign those strings to file and tell us what happens when you type img = dicomread(file) at the command prompt.