I am working on a matrix on Gate Level Delay Computing-Commom Subexpression Elimination (GLDC-CSE)

1 view (last 30 days)
my matrix is
mat=[0 0 0 0 0;0 0 -1 0 0;0 0 -1 -1 -1;0 0 -1 0 -1;-1 -1 0 -1 -1]
I have written code for CSE, I have to apply GLDC now. It consist of an algorithm in which suppose the row is ar=[0 0 -1 0 0]
  1. I have to sort the row after sorting [-1 0 0 0 0]
  2. then have to take two positive delay values here it is d1=0 and d2=0
  3. The initial delay will be di=-1 and finaldelay=max(d1,d2)+1.
  4. then repeat repeat steps 2 to 4 till u get one positive value.
Explation: after sorting [-1 0 0 0 0]; d1=0 and d2=0; so di=-1 and finaldelay=max(0,0)+1=1.row[-1 -1 1 0 0]
Again sorting [-1 -1 0 0 1]; d1=0 and d2=0; di=-1 finaldelay=max(0,0)+1=1.so[-1 -1 -1 1 0]
again sorting [-1 -1 -1 0 1];d1= 0 and d2=1; di=-1 finaldelay=max(0,1)+1=2 so [-1 -1 -1 -1 2].
I am not able to extract two positive elements and replace it with -1.
Any kind of help will help me.
Thanks!!!
  6 Comments
Rutika Titre
Rutika Titre on 22 Nov 2015
Hello sir, I have written this code...it is working partially.I just want your help how should I go back to the starting of the loop. I have read continue and while loop these are the two things i can use.where to use continue to start the loop again or while loop.Help plz
x=[0 0 -1 0 0]; s=sort(x); T=zeros(size(s)); for ii=1:numel(s) if s(ii)==-1 T(ii)=-1; continue; end % ii=ii+1; if s(ii)==0 d1=0; T(ii)=-1; end ii=ii+1; if s(ii)==0 d2=0; difi=max(d1,d2)+1; T(ii)=difi; break end
if s(ii)>0
d3=s(ii);
fidi=max(d2,d3)+1;
T(ii)=fidi;
break
end
end
R=sort(T);
ii=ii+1;

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 12 Nov 2015
Your code has
d1=ar(ar(j:j+1)>=0);
You are examining two positions, out of which 0, 1, or 2 values will be >= 0. You are selecting those elements into d1.
You take d3=max(d1) . If the vector is length 1 or 2 then that is okay, you would get a scalar that contained the maximum. But if the vector was of length 0, then max() of the empty vector will be empty. And then you do difi=d3+1 . If none of the d1 values were >= 0 then d3 came out empty, and empty + 1 is empty. You then try to go around storing that emptiness into real locations...

Tags

Community Treasure Hunt

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

Start Hunting!