How to determine the index of a vector with range from 1
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
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
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);
input size error in neural network programming by MATLAB
What does #() in front of a matrix?
feature map generation
' vectors must be the same length' error
the range of Theta & Phi angles in Spherical Coordinates matlab?
mask a portion of image in matlab?
visualise Orientation map with opencv or matlab
/usr/bin/ld cannot find lib files when compiling openCv matlab source
libfaad2.dll is not a valid win32 application - dependency error kernel32.dll
Moving a 3-D Object Along a Path in MatLab [duplicate]
Is there a way to subtract from spectrogram (stored as a figure) from another in MATLAB?
Matlab: generating a monte carlo sample from a defined model
Cuda matrix multiplication results differs from MATLAB
Clickable/ Interactive contour plots in Matlab
Writing a function such that it can be applied to a grid
MATLAB's 'solve,' applied to a system of equations, gives me a solution that doesn't satisfy one of the equations