Can anyone suggest a solution? I was trying to convert it into the adjacency matrix and then make a heatmap from that. But that was giving me some weird adjacency matrix with many 0 values and hence a wrong heatmap as well. Since I am new to MATLAB, I would appreciate it if you have any ideas. Thank you.
How to convert the graph below in to heatmap?
4 次查看(过去 30 天)
显示 更早的评论
I have the graph below. It was plotted using the code below:
%% matrix (:,4) is the weight of the corresponding matrix(:1:2) branches. Ignore matrix(:,3).
nodes = [];
for i = 1:1:size(matrix,1)
if matrix(i,4) <= 10000
nodes = [nodes,matrix(i,1:2)];
end
end
nodes_cellarray{:} = nodes;
set(figure, 'Visible', 'on');
Graph = graph(matrix(:,1),matrix(:,2));
plot_array = plot(Graph, 'layout', 'auto');
% plot_array.EdgeColor = 'red';
highlight(plot_array,nodes_cellarray{:},'EdgeColor','r','NodeColor','r','LineWidth',4);
I have attached the matrix23.xlsx file that has the matrix 'matrix' used above.
2 个评论
Deepak Kumar
2020-1-3
Refer the below MATLAB documentation link to get more insight about "heatmap" function
采纳的回答
Walter Roberson
2020-1-3
t = readtable('matrix23.xlsx');
mask = t{:,3} == 65535 | t{:,4} == 65535;
t(mask,:) = [];
figure(1)
h = heatmap(t, 'Var1', 'Var2', 'ColorVariable', 'Var3');
h.GridVisible = false;
figure(2)
subplot(1,3,1);
scatter(t{:,1}, t{:,2}, [], t{:,3});
title('scatter');
A = sparse(t{:,1}, t{:,2}, t{:,3}, 2600, 2600);
subplot(1,3,2)
spy(A);
title('normal spy');
subplot(1,3,3)
r = symrcm(A);
spy(A(r,r));
title('spy symrcm');
3 个评论
Walter Roberson
2020-1-3
编辑:Walter Roberson
2020-1-3
Add the option
'readvariablenames', false
To the readtable call. Then the four variables will be Var1 Var2 Var3 Var4. You can reassign the variable names by changing
t.Properties.VariableNames
I assumed that the first column correeponds to x values and the second corresponds to y values and the third corresponds to z values with the fourth being unknown purpose.
You got the x1 and x52 variables because readtable() did not notice that the first row was purely numeric and assumed that the first row was a header line giving the variable names. In sufficiently new versions of MATLAB, readtable() does recognize that the first line is completely numeric and does not create variable names from the data, equivalent to having specified 'readvariablenames', false
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!