error in import data
Show older comments
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 Comment
Stephen23
on 30 Dec 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.
Accepted Answer
More Answers (2)
Sulaymon Eshkabilov
on 30 Dec 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 Comment
xin wang
on 30 Dec 2022
Sulaymon Eshkabilov
on 30 Dec 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
Categories
Find more on Image Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!