Easy Visualization of rows of a matrix or more matrices
plot_array function plots in a single figure all rows of the variable X
inputs:
X = matrix [n x m] % n: channels and m: samples
- if the first row is monotonical increasing it will be used as
x axes (e.g. time)
if X is a cell array of matrix with the same size each row of each
cell will be held on the same line
IxRow = cell array of n cells string used for specifying ylabels
TITLE = is a string used as the title of the first subplot
Y_LIMITS = two elements vectors indicating the ylim for each row
outputs:
F_handle = figure's handle
------------
% examples:
% ------------
% plot a matrix of 10 channels and 500 samples
X = rand(10,500);
plot_array(X)
%% ------------
% plot two matrixs of 10 channels and 500 samples
A = rand(10,500);
B = rand(10,500);
X = {A;B};
F_handle=plot_array(X);
%% ------------
% plot two matrixs of 5 channels and 500 samples with ylabels defined as
% the name of the fingers. The title will be defined by the variable TITLE
% and the y axis in the range [-1 1]
A = rand(5,500)-0.5;
B = rand(5,500)-0.5;
IxRow = {'Thumb','Index','Middle','Ring','Little'};
TITLE = 'Fingers Value';
Y_LIMITS = [-1 1];
X = {A;B};
F_handle=plot_array(X,IxRow,TITLE,Y_LIMITS);
%% ------------
% plot one matrix of 5 channels and 100 samples with the first row
% monotonical increasing (used as x axes). And set the y limits as [-15 15];
A = (rand(5,500)-0.5)*15;
dt = 0.01; % step time
Time = dt:dt:length(A)*dt;
X = [Time;A];
Y_LIMITS = [-15 15];
F_handle=plot_array(X,[],[],Y_LIMITS);
%
%% ------------
% plot two matrixs of 5 channels and 100 samples with the first row
% monotonical increasing (used as x axes). And set the y limits as [-15 15];
% And add the legend of the two signals
A = (rand(5,500)-0.5)*15;
B = (rand(5,500)-0.5)*10;
dt = 0.01; % step time
Time = dt:dt:length(A)*dt;
X = {[Time;A],[Time;B]};
Y_LIMITS = [-15 15];
IxLegend = {'Signal A','Signal B'};
F_handle=plot_array(X,[],[],Y_LIMITS,IxLegend);
Author:
Michele Barsotti, PhD student at PERCRO laboratory,
Scuola Superiore Sant'Anna, Pisa, ITALY.
Matlab 2014 is required for changing colors of cell inputs
Cite As
Michele (2024). Easy Visualization of rows of a matrix or more matrices (https://www.mathworks.com/matlabcentral/fileexchange/56687-easy-visualization-of-rows-of-a-matrix-or-more-matrices), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Signal Processing > Signal Processing Toolbox > Spectral Analysis > Parametric Spectral Estimation >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.