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

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 Kommentare

Can any1 plz hep me out with this algorithm.I am really not getting hoe to implement in code. the problem is how to get the to zero elements from row vector and apply this algorithm. And the how to repalce it values. plz help.
arr=[ 0 0 -1 0 0];
[r,c]=size(arr);
for i=1:length(arr)
ar=sort(arr);
j=1;
d1=ar(ar(j:j+1)>=0);
j=j+1;
d3=max(d1);
difi=d3+1;
d1(1)=-1;
d1(2)=difi;
dd(1)=d1(1);
dd(j+1)=difi;
end
I am trying but still the elements are not getting incremented...plz help
thank u Sir for replying..Sir I know 0 is not positive value but my matrix contains only 0 and -1 and have to apply the algorithm on the whole matrix. I working on only 1 row as of now.but m not able to get 2 zero and increment to next position.Can u plz help in this plz.I have tried usinf max, [svalues idx] to get 2 largest value of a row vector and after getting it to increment it to next 2 large numbers.Help Sir plz..
"2. then have to take two positive delay values here it is d1=0 and d2=0"
But 0 is never a positive delay value.
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;

Melden Sie sich an, um zu kommentieren.

Antworten (1)

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...

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 5 Nov. 2015

Kommentiert:

am 22 Nov. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by