필터 지우기
필터 지우기

Plotting Binary Variables using Heat Map

조회 수: 17 (최근 30일)
Tochi Nwachukwu
Tochi Nwachukwu 2023년 1월 19일
답변: Varun 2023년 2월 21일
I do need assitance plotting binary variables using heatmap. Please attached data sheet
The plot generated from the code below is not what want.
Mpower4 = readtable('file.xls','Sheet','Connectivity','ReadRowNames',true,'EmptyValue',0,"TextType","string" );
Vars = {{'g1','g2','g3'},{'G2crank','G3crank'},{'n1','n2','n3','n4','n5','n6','n7','n8','n9'},{'l1','l2','l3','l4','l5','l6','l7','l8','l9'}};
s5=stackedplot(Mpower4,Vars);
s5.LineProperties(1).PlotType = "stem";
s5.LineProperties(2).PlotType = "stairs";
s5.LineProperties(3).PlotType = "stairs";
s5.LineProperties(4).PlotType = "stairs";
ax3 = findobj(s5.NodeChildren, 'Type','Axes');
set(ax3, 'YTick', [0 1]);
s5.AxesProperties(1).YLimits = [-0.5 1.5];
s5.AxesProperties(2).YLimits = [-0.5 1.5];
s5.AxesProperties(3).YLimits = [-0.5 1.5];
s5.AxesProperties(4).YLimits = [-0.5 1.5];
s5.LineWidth = 2;
s5.XLabel ='Minutues'
grid on

채택된 답변

Varun
Varun 2023년 2월 21일
Hello!
To plot a heatmap of binary variables, you can convert the table data to a matrix (array) first and then, call the heatmap function directly. Check out the following code:
Mpower4 = readtable('matlabhelp.xlsx','Sheet','Sheet1','ReadRowNames',true,'EmptyValue',0,"TextType","string" );
mp4=Mpower4{:,:};
xvalues={'g1','g2','g3','G2crank','G3crank','n1','n2','n3','n4','n5','n6','n7','n8','n9','l1','l2','l3','l4','l5','l6','l7','l8','l9'};
yvalues=1:14;
h=heatmap(xvalues,yvalues,mp4);
For more information about heatmaps on MATLAB, check out the following documentation: https://www.mathworks.com/help/matlab/ref/heatmap.html#bvlbhnq-1
Hope this helps!Heatmap of binary variables

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by