error in import data
显示 更早的评论
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 个评论
Stephen23
2022-12-30
"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.
采纳的回答
更多回答(2 个)
Sulaymon Eshkabilov
2022-12-30
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
Sulaymon Eshkabilov
2022-12-30
(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
类别
在 帮助中心 和 File Exchange 中查找有关 Image Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
