I went back to the drawing board and figured out a way to do it. :-) Here's what I came up with. (Thank you dpb for all the time and effort and patience in working on this. I may not have communicated clearly what I was trying to do.)
% Create an index for values that are within-category and another index
% for those that are between categories
idxwithin = zeros(size(label_matrix)); %create a matrix of zeros the size of label_matrix to hold markers for values that are within the same category
idxbetween = zeros(size(label_matrix)); %create a matrix of zeros the size of label_matrix to hold markers for values that are NOT within the same category
for column = 2:length(label_matrix) %loop across each column header
for row =2:length(label_matrix) %loop down each row header
if label_matrix(1,column) == label_matrix(row,1) %if column header = row header...
idxwithin(row,column) = 1; %enter 1 at the intersection of row,column into the 'idxwithin' matrix
else
idxbetween(row,column) = 1; %otherwise enter 1 at the intersection of row,column into the 'idxbetween' matrix
end
end
end
idxwithin = logical(idxwithin); %convert idxwithin matrix into a logical
idxbetween = logical(idxbetween); %convert idxbetween matrix into a logical
% find the means of within- and between-category values
withinCatMean = mean(label_matrix(idxwithin),'all','omitnan') %calculate the mean of the within category values from label_matrix, exluding NaNs
betweenCatMean = mean(label_matrix(idxbetween),'all','omitnan') %calculate the mean of the between category values from label_matrix, exluding NaNs
