10 views (last 30 days)

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.

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');

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

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/498570-how-to-convert-the-graph-below-in-to-heatmap#comment_782264

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/498570-how-to-convert-the-graph-below-in-to-heatmap#comment_782264

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/498570-how-to-convert-the-graph-below-in-to-heatmap#comment_782734

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/498570-how-to-convert-the-graph-below-in-to-heatmap#comment_782734

Sign in to comment.