I have a symmetric matrix of some statistical values that I want to plot using imagesc in Matlab. The size of the matrix is 112 X 28, meaning I want to display 4 rows for each column. How can I get rid of the upper or lower triangular part of this matrix ? Since this means deleting 4 rows per each column diagonally tril or triu functions does not work (they are for square matrices). Thanks
You can use kron function
kron(triu(ones(28)),[1 ;1 ;1 ;1])
If you have the Image Processing Toolbox you could use imresize to resize an upper triangular mask that you can then use to select the appropriate data
msk = imresize(triu(true(min(size(a)))), size(a), 'nearest');
% Just zero-out the lower diag
zeroed = msk .* a;
% Select the elements in the upper diagonal
upperdiag = a(msk);
If you don't have the Image Processing Toolbox (and imresize) you can do something like
msk = reshape(repmat(permute(triu(true(min(size(a)))), [3 1 2]), size(a,1)/size(a,2), 1), size(a));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With