error in import data
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
xin wang
am 30 Dez. 2022
Kommentiert: Stephen23
am 30 Dez. 2022
When I use the code to deal with a series of ".TIFF" document, it usually shows in the format of " error in importdata", and it cannot open the document. I really want to know where the question is. I have named the data with the format of "CPline" in another file, and whether my code cannot open the "CPline" file. Thank you for my question!
clc
clear all
close all
% Assignments
zdimension = input('Number of .tif images? ');
% Subvolume is the region in which 3D data will be cut around three-phase
% contact point
subvolume = input('Dimension of subvolume? ');
subvolume = subvolume/2;
mydata = cell(1, zdimension);
% Import .tif images in MATLAB
% !!If different number of figures, change %03d!!
for k = 1:zdimension
myfilename = sprintf('CPline%03d.tif', k);
mydata{k} = importdata(myfilename);
end
1 Kommentar
Stephen23
am 30 Dez. 2022
"Put all the files in the same directory or folder where you are running the code."
Ugh, do NOT clutter up your MATLAB search path with lots of data files. Keep your data and code separate!
Every MATLAB function that imports/exports data files also accepts absolute/relative filenames, which is exactly what you should do. As Sulaymon Eshkabilov wrote, you will find FULLFILE() very useful for this.
Akzeptierte Antwort
VBBV
am 30 Dez. 2022
mydata{k} = imread(myfilename);
3 Kommentare
VBBV
am 30 Dez. 2022
Bearbeitet: VBBV
am 30 Dez. 2022
- Put all the files in the same directory or folder where you are running the code.
- Check whether the filenames exist in the working folder. As you are using number range upto zdimension imread checks for all filenames upto that range.
- I guess your first filename may be CPline1.tif instead of CPline001.tif. Because you are using format specifier of %03d sprintf command searche for filenames that have trailing 3 digits padded with zeros. For filenames upto 1 to 10, it will search for CPline001.tif in the folder as mentioned before. To avoid it, change it to %d
- In such case rename those filenames to CPline001.tif so on ... CPline009.tif. Similarly from 10 to 20 it should be CPline010.tif and so on... CPline099.tif.
Weitere Antworten (2)
Sulaymon Eshkabilov
am 30 Dez. 2022
Here is the corrected part of your code (supposedly all of your tif images are in your current directory of matlab):
...
for k = 1:zdimension
myfilename = strcat(['CPline' num2str(k) '.tif']);
mydata{k} = imread(myfilename);
end
1 Kommentar
Sulaymon Eshkabilov
am 30 Dez. 2022
(1) Copy the files and paste them into your matlab directory
Or
(2) Use fullfile() fcn, e.g.:
FILE = fullfile('C:\Users\', '*.tif'); % Directory where the files are residing
% IMAGE_DS = imageDatastore(FILE); % Optional
LIST = dir(FILE);
N = length(LIST); % N = zdimension;
% D = zeros(250, 250, N); % Optional: If your tiff images are too large. Memory allocation for the RESIZED Images to be read
for ii = 1 : N
FFName = fullfile(LIST(ii).folder, LIST(ii).name);
DATA = imread(FFName);
% DATA = imresize(DATA(:,:,1), [250, 250]); % Optional
D{ii} = DATA;
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!