Reputation: 1485
I have a question a the way to determine the index of a vector in matlab. Let see the my problem as the figure. I have a 6 bits that includes 2 parts: red part and blue part. Size of red part is |S1| and blue part is |S2|(ex: |S1|=2 and |S2|=4). The index of original bits (6 bits) from 0 to l . Now, I dumplicate the red part twice time and blue part 1 time to make the below bit with index from 0 to j. Size of red part is RF1*|S1| and blue part is RF2*|S2|. (ex: RF1=2 and RF2=1). Given a index in the below bits (from 0 to j), we can determine the index l of them in the original bit by the formula in the figure.
For example, If the index of a selected information symbol is, for example, 5, we map it to 5 mod 4+2=3 (red arrow) However, the index of problem is from 0. As you know, the index of a vector in matlab will starts from 1. So I changes it as the below figure. My problem is that how to find index l if given index j it by matlab code using second scheme (index from 1). I done it but it looks complex
For index starts from 1, we can see that I want to map index j=6 to l=4 This is table example
This is my code
function l=find_index(j,S1,S2,RF1,RF2)
if j<(RF1*S1-1)
l=mod(j,S1);
if l==0
l=S1;
end
else
l=mod(j,RF2*S2)+S1 ;
if l==0
l=S2;
end
end
end
Upvotes: 1
Views: 77
Reputation: 1257
maybe this?
function l=find_index(j,S1,S2,RF1,RF2)
if j<=(RF1*S1)
l=mod(j-1,S1)+1;
else
l=mod(j-RF1*S1-1,S2)+S1+1;
end
end
Upvotes: 1
Reputation: 45741
Firstly S2
is always positive is it not? Which means that l=mod(d,RF2*S2)+S2
can never equal zero making the check that follows unnecessary. Secondly you can transform the first mod
to include the check like so: l=mod(d-1,S1)+1;
so putting it all togehter:
if j<(RF1*S1-1)
l=mod(j-1,S1)+1;
else
l=mod(j,RF2*S2)+S2;
end
which is probably the right answer without re-examining your logic (which I could not follow). However if for some reason you really really want a one liner:
l= (j<(RF1*S1-1))*(mod(j-1,S1)+1) + (j>=(RF1*S1-1))*(mod(j,RF2*S2)+S2);
Upvotes: 1