I'm guessing you want a list of indices where your ships are located. This list would have as many entries as the total sum of all the length of your ships. Note that MATLAB can do 1D indexing on multi-dimensional arrays, so if you have a 2x2 grid, you can get the parameters by calling a single index, e.g.:
a = magic(2);
for i = 1:numel(a)
disp(strcat("i: ", string(i), ", a(i): ", string(a(i))));
end
If you assign each ship to a spot in your 6x6 grid, then you can save a vector of all the indexes where your ships are located. Then, when in your gui someone selects a specific point, you can check if that point is in your list and do any following actions.
N = 6;
ships_at = [1, 2, 3, 9, 15, 21, 27];
clicked_on = [4, 3]; %row column of click
index = clicked_on(1)*N + clicked_on(2);
hit = sum(ships_at == index) == 1;
if hit
% Do something if a ship gets hit here
end