Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% code for SO question: http://stackoverflow.com/questions/24744959
- clear
- %% generate testing data
- [X,Y] = ndgrid(1:20); testdata = [X(:) Y(:)]; % all possible edges
- testdata(testdata(:,1)==testdata(:,2),:)=[]; % delete self loops
- testdata=testdata(randperm(size(testdata,1),30),:); % take random sample of edges
- testdata(:,3)=rand(size(testdata,1),1)*10; % assign random weights in range 0-10
- %% get data into useable format
- edges=testdata(:,1:2); %
- [Verticies,~,indEdges]=unique(edges);
- indEdges=reshape(indEdges,[],2);
- weights=testdata(:,3);
- normalisedWeights=weights/max(weights);
- numeEdge=numel(weights);
- numVertex=numel(Verticies);
- %% create x,y coordinates for each vertex
- theta=linspace(0,2*pi,numVertex+1);
- theta=theta(1:end-1);
- [x,y]=pol2cart(theta,1);
- %% create axis colour order
- colormap('autumn')
- Cmap(:,2)=normalisedWeights;
- Cmap(:,1)=1;
- Cmap(:,3)=0;
- %% plot edges
- figure
- colormap('autumn')
- hold on
- set(gca,'colororder',Cmap) % set axis colororder to Cmap
- hline=plot(x(indEdges).',y(indEdges).'); %plot edges
- axis square off
- set(gca,'Clim',[0 max(weights)])
- colorbar %set colour limit to match weight & add colorbar
- scalefactor=5; %// scale factor (width of highest weight line)
- set(hline, {'LineWidth'}, num2cell(normalisedWeights*scalefactor));
- %% plot Verticies
- plot(x,y,'ks')
- xlim([-1.1,1.1]) % expand axis to fix labels
- ylim([-1.1,1.1])
- text(x(:)*1.1, y(:)*1.1, num2str(Verticies), 'FontSize',8,'HorizontalAlignment','center');
- % add Vertex labels
Add Comment
Please, Sign In to add comment