Only upper triangle part of plotmatrix function

Hello, Is it possible to only plot the upper triangle part of the matrix plots when using 'plotmatrix' function? matrixplot generates an m by m subplots, however, the lower scatter subplots (lower triangle plots) are the mirror image of the upper triangle subplots. For large number of data set in the input matrix, the default option including bother upper and lower subplots will be very slow.
Many thanks.

 Accepted Answer

I had a similar issue of only wanting to plot the bottom half of the matrix. Like you said H H the plotmatrix function outputs objects so I just used the function like normal and then deleted the handles. For me it was the visual presentation of the chart, but I don't think this will solve the problem of slowness due to the large amount of data (unless you are zomming/panning around looking at the data once its in the plot).
Lets take a 4x4 plot matrix. The excel plot below is how gplotmatrix assigned the axes handles. The axes handles start at 2 and go right to left. I wanted to delete the ones in yellow because they present the same data as the lower half just with flipped axes.
Capture.PNG
So I needed to collect each handle I didn't want and then deleted them.
h = figure(123);
% gplotmatrix(...) % this is obviously uncommented, I just don't know what your inputs are
M = length(gplotNAMES); % M length of matrix
ii=1; indexEND=0; % initial counters
while (M-ii-1) >= 0
indexSTART = indexEND + ii; % start index for each row
indexEND = indexSTART + (M-ii-1); % end index for each row
index2delete{ii} = indexSTART:indexEND; % collect the indices for each row (ii)
ii=ii+1;
end
% convert cell to a vector, you just need all the indices. Not necessarily by row
indDELETE = cell2mat(index2delete)+1; % add 1 because the axes objects start at 2
delete(h.Children(indDELETE)) % delete all handles in indDELETE
I hope this helps! I know your submission is ~2 years old, but I figured it would be nice to see an answer at some point!
-Ryan

3 Comments

In 2021, there is a simpler way to do this, or at least a way that is easier to understand. The plotmatrix function can optionally return the handles to the plots it creates. Below, AX refers to a matrix where each entry is the handle to one of the individual scatterplots, which can be accessed with the familiar (row, column) indexing.
Here is example code to delete the ones in the upper right triangle:
%create some dummy data with 6 columns and 100 rows
MyDataMatrix = randn(100, 6);
%create a plot matrix of MyDataMatrix
[S,AX,BigAx,H,HAx] = plotmatrix(MyDataMatrix);
%get the number of columns, n, in MyDataMatrix
[m, n] = size(MyDataMatrix);
% Your plot matrix will have n x n little plots,
% matching the number of columns in your data matrix.
% Loop over every plot in the plot matrix, and delete the ones
% in the "upper right triangle,"
% i.e. where the column index is greater than the row index.
for plot_row = 1:n
for plot_col = plot_row:n
delete(AX(plot_row, plot_col));
end
end
I'm all for simplier! That works beautifully. Thanks Matthew!
Thank you that’s great

Sign in to comment.

More Answers (1)

doc triu and tril, it gives upper and lower triangular part of a matrix respectively.

2 Comments

H R
H R on 27 Jul 2017
Edited: H R on 27 Jul 2017
Thanks KSSV. But this won't work. plotmatrix will be an object of size m by m and triu won't work.
Did any one find a solution to this?

Sign in to comment.

Products

Tags

Asked:

H R
on 26 Jul 2017

Commented:

H R
on 29 Jan 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!