Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to plot a graph in matalab2016?

조회 수: 1 (최근 30일)
SUNANNA S S
SUNANNA S S 2017년 5월 18일
마감: MATLAB Answer Bot 2021년 8월 20일
When I use plot() it gives an error that the value is not integer.
I want to plot the graph
E=[0.0236;0.0485;0.0889;0.569;0.789;0.894;1]
and
top=[10%;15%;20%;30%;40%;50%]
Please help.
  댓글 수: 2
KSSV
KSSV 2017년 5월 18일
Show us the complete code...which you tried...
SUNANNA S S
SUNANNA S S 2017년 5월 21일
Actually I'm trying to implement the PageRank algorithm in my code . But this gives an error. Please help. I want to plot the graph of Eap on y axis and top on x axis.
clc;
% n = 6;
% i = [2 6 3 4 4 5 6 1 1];
% j = [1 1 2 2 3 3 3 4 6];
load Eapfinal.mat;
top=[0.10,0.15,0.20,0.30,0.40,0.50];
s=top;
t=Eap;%Eap=0.0136,0.0503,0.1761,0.2724,0.2985,0.2986
n=6;
G = sparse(s,t,1,n,n);
spy(G)
%%Page Rank
p = 0.85;
delta = (1-p)/n;
c = sum(G,1);
k = find(c~=0);
D = sparse(k,k,1./c(k),n,n);
e = ones(n,1);
I = speye(n,n);
x = (I - p*G*D)\e;
x = x/sum(x);
%%Bar graph
bar(x);
title('Page Rank');
The error I get after running this code is
Error using sparse
Index into matrix must be an integer.
Error in PageRankafter (line 13)
G = sparse(s,t,1,n,n);

답변 (2개)

Rik
Rik 2017년 5월 18일
In general you should copy the entire error stack (all the red text). This makes it easier for others to understand what went wrong.
I noticed 2 things:
  • the percent sign marks the beginning of a comment, so top will not be correctly assigned (although I assume that you already did top=[0.10,0.15,0.20,0.30,0.40,0.50];)
  • E has 7 values, while top has only 6. It is impossible for plot to know what xy-pairs to make.

Walter Roberson
Walter Roberson 2017년 5월 21일
The call
G = sparse(s,t,1,n,n);
means that you want to create the sparse matrix equivalent of
G = zeros(n, n);
for K = 1 : length(s)
G( s(K), t(K) ) = 1;
end
That can only work if all of the elements of s and all of the elements of t are positive integers, but they are not: they are values like 0.10 and 0.0136
It is difficult to say exactly what your replacement code should be. Possibly
Gs = sparse(i, j, s, n, n);
Gt = sparse(i, j, t, n, n);
if the intention is to create sparse matrix that has the values in s stored at the i and j locations, an that has t stored at the i and j locations. Sparse matrices cannot be multi-dimensional: you can only store a single value at any one index pair.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by