MATLAB: How to select different data points in different images in a loop

getptsMATLAB

I wish to select a different number of data points for different image in this loop but I can't do that since it gives me an error "Unable to perform assignment because the size of the left side
is 3-by-1 and the size of the right side is 4-by-1.". Is there a way to make the 3-by-1 to 4-by-1 by adding zeros as needed?
clear
clc
close all
% Read images in order from 1 to 925.
% Files are in the "myFolder" directory.
imageFolder = 'D:\Research File\September 26\C001H001S0001';
for k = 1:925
tifFilename = sprintf('C001H001S0001000%03d.tif', k);
fullFileName = fullfile(imageFolder, tifFilename);
if exist(fullFileName, 'file')
imageData = imread(fullFileName);
Pic=imageData/64;
else
warningMessage = sprintf('Warning: image file does not exist:\n%s', fullFileName);
uiwait(warndlg(warningMessage));
end
image(Pic);
colormap(bone);
xlabel('$x$','fontsize',24,'interpreter','latex');
ylabel('$y$','fontsize',24,'interpreter','latex');
[i(:,k),j(:,k)]=getpts;
end

Best Answer

I don't think a zeropad approach would be optimal, the main problem is that your vector can increase size every time as the same time as your inputs can be smaller. To solve this you can use a cell array which can hold different size vectors without problem. This code solves your problem:
clear
clc
close all
% Read images in order from 1 to 925.
% Files are in the "myFolder" directory.
imageFolder = 'D:\Research File\September 26\C001H001S0001';
i = cell(925,1);
j = cell(925,1)
for k = 1:925
tifFilename = sprintf('C001H001S0001000%03d.tif', k);
fullFileName = fullfile(imageFolder, tifFilename);
if exist(fullFileName, 'file')
imageData = imread(fullFileName);
Pic=imageData/64;
else
warningMessage = sprintf('Warning: image file does not exist:\n%s', fullFileName);
uiwait(warndlg(warningMessage));
end
image(Pic);
colormap(bone);
xlabel('$x$','fontsize',24,'interpreter','latex');
ylabel('$y$','fontsize',24,'interpreter','latex');
[i{k},j{k}]=getpts;
end