How can I code this without exceeding matrix dimensions?
Ältere Kommentare anzeigen
Hello!
I am trying to write a type of scrambling code, and below is an image of the desired functionality. The functionality of this particular scrambling code was included in a documentation about 3G networks.
I am having difficulty trying to code the fifth dot point, regaring the n:th Gold code sequence, z(i). n is some integer, between 0 and 2^18 -2, (or when coded in MATLAB, between 1 and 2^18 -1).
I am not sure if I am understanding the code in the image correctly, but it seems like in the z(i) line, I am trying to access an element of x that is beyond it's size?
I have also attached the code I have written in MATLAB so far. When I run it, I receive an error saying "Index exceeds matrix dimensions," and it is because of the z(i) line.
I hope anyone can help me. I appreciate any ideas or help. Thank you! :')
x(1)=1;
for i=2:18
x(i)=0;
end
for i=1:18
y(i)=1;
end
for i=1:262125
x(i+18) = mod(x(i+7) + x(i), 2);
y(i+18) = mod(y(i+10) + y(i+7) + y(i+5) + y(i), 2);
end
%from below, there is an indexing issue, it exceeds dimensions...
n=1:262143;
for i=1:262143
z(i) = mod(mod(x(i+n), 262143) + y(i), 2);
end

4 Kommentare
Walter Roberson
am 12 Nov. 2020
z(i) = mod(mod(x(i+n), 262143) + y(i), 2);
You are calculating i+n and indexing x with it, and when that succeeds you retrieve content from x and mod() that with 262143. The you add y(i) to the result, and mod() that with 2.
However, your text says that what you need to do is calculate i+n and take that mod 262143 and use the mod() to index x, get back content. You retrieve y(i) and take it mod 2, and add that to the cotnent retrieved from x.
Important note:
The text talks in terms of x(0) but in MATLAB 0 is not a valid index. For MATLAB, you need to add 1 to every index that is used in the text. For example when it talks about x(i+18) with i starting from 0, then if you use i starting from 0, you need to access x(i+18+1) -> x(i+19) -> x(19)
Mich Elly
am 13 Nov. 2020
Walter Roberson
am 13 Nov. 2020
That does look better -- just keep in mind that for that to work, i will have to be at least 1, and that where the text talks about x(0) or y(0) they are talking about the "first" x or y, which would be x(1) and y(1) . So if your i starts from 0 then you should be using
x(i+18+1) = x(i+7+1) + mod(x(i+1),2);
y(i+18+1) = y(i+10+1) + y(i+7+1) + y(i+5+1) + mod(y(i+1), 2);
Mich Elly
am 15 Nov. 2020
Antworten (0)
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!