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?
1 view (last 30 days)
Show older comments
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.
![figure23.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/257764/figure23.jpeg)
2 Comments
Deepak Kumar
on 3 Jan 2020
Refer the below MATLAB documentation link to get more insight about "heatmap" function
Accepted Answer
Walter Roberson
on 3 Jan 2020
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 Comments
Walter Roberson
on 3 Jan 2020
Edited: Walter Roberson
on 3 Jan 2020
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
More Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!