Index in position 2 exceeds array bounds (must not exceed 1).
2 次查看(过去 30 天)
显示 更早的评论
Hello!
I am getting an error while running the code as given below"
Index in position 2 exceeds array bounds (must not exceed 1).
Error in Untitled4 (line 32)
imagesc(data{1,3});
The main code is:
% A = imread('Filename');
%%
close all;
load_data_flag =1;
%% Load data
if load_data_flag ==1;
%
% las_file = load('Curves.txt');
% log_depth = las_file(:,1);
% caliper3 = las_file(:,3:5); % 1) depth, 3-4-5) calipers
% caliper_ave = mean(caliper3(:,3:end),2);
%%
tifffiles = dir('*.tif');
nfiles = length(tifffiles);
for n= 1:nfiles;
data{n} = imread(tifffiles(n).name);
end % endfor
% concatenate all log data into one matrix
% DATA = data;
DATA = data{1,1};
for i = 2:length(data(1,:))
DATA=vertcat(DATA,data{1,i});
end
%% Subsection of data
clf
imagesc(data{1,3});
reply = input ('Input depth axis, subsection and 0-360 coordinates?[Y]/[N]:', 's');
if reply == ('Y')||('y')
I would appreciate if anyone can help?
0 个评论
采纳的回答
Walter Roberson
2020-7-24
You only have one .tif file in your current directory so you are only storing data{1} .
5 个评论
Walter Roberson
2020-7-24
load_data_flag = 1;
%% Load data
if load_data_flag == 1
force_rows = 512; force_columns = 512;
tifffiles = dir('*.tif');
nfiles = length(tifffiles);
data = cell(nfiles, 1);
for n = 1:nfiles
input_image = imread(tifffiles(n).name);
data{n} = imresize(input_image, [force_rows, force_columns]);
end % endfor
% concatenate all log data into one matrix
DATA = cat(ndims(data{1})+1, data{:});
end
This code forces all images to be the same size, controlled by force_rows and force_columns. Using a fixed aspect ratio can distort the image. You should think more about how you want to handle the case where the images are not the same size. Sometimes it makes sense to imresize() them to a common size. Sometimes it makes more sense to pad them to a common size. Sometimes it makes more sense to pad them as needed to fit the widest and heighest image. Sometimes it makes most sense to pad relative to the center rather than padding on bottom or right all the time. Sometimes it makes more sense to do image registration to find the best scaling and translation to bring them into alignment.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!