-1

I get some strange problem in my matlab code, this is a part of my code:

for k=1:length(box11)
    num_pts1(k)=sum(length(find(box11(:,k)>0)));
    size1=sum(length(find(box11(:,:)>0)));
    perc1(k)=(num_pts1(k)/size1)*100;
end
plot(delta,perc1(k),'*')

However, the problem is that I get perc1 fixed in my plot. so I see a straight line in the graph. but I would like to have different numbers which give a curve line to me.. plzzzzzzzzzzzzzzzz, any help :( !!!

PLS
  • 15
  • 1
  • 5
  • Two things are unclear to me: The result you are trying to get vs. what you get and what `box11` is. Please be clearer on that. (Attaching the plot you get might help) – gzm0 May 09 '13 at 20:42
  • Hi, this is box11: box11=flipud(full(sparse(delta11,Sref11,delta11))); where delta11 and Sref11 are two matrixces 51*1 – PLS May 09 '13 at 20:50
  • Do you mean `plot(delta,perc1,'*')` ? otherwise you are just plotting a single point, `perc1(k)` where `k` is `legnth(box11)`. Also what is `delta`? – Dan May 09 '13 at 21:44
  • the code which I added gives me a straight line, which means that k is fixed.. while it should be a curve because k is changing every loop.. hope that I could explain it now :) !! – PLS May 10 '13 at 02:50
  • No help until now :( :( :( – PLS May 10 '13 at 08:37

1 Answers1

0

You should recall that length returns the length of an array. So, in the instruction

num_pts1(k)=sum(length(find(box11(:,k)>0)));

the operator sum acts on a scalar (which equals the length of the array find(box11(:,k)>0)), and not on an array. The same holds true for the instruction

size1=sum(length(find(box11(:,:)>0)));

So, if the length of find(box11(:,k)>0) does not change with k, then your perc1 will keep constant.

Vitality
  • 20,705
  • 4
  • 108
  • 146