Saving values after each iteration

  • Thread starter gryphon1221
  • Start date
In summary, the student is trying to find a way to store each "k" value before the next iteration begins so that he will have a vector of all the values. He has it set up for 32 iterations, but eventually needs about 7000 so an automatic process is necessary. He has code that stores the values in an array, but is having trouble getting it to work.
  • #1
gryphon1221
9
0
Hello, I am taking a class on GPS navigation. Our homework is to construct a signal based on 10 initial condition values and use modelo-2 arithmetic to get each subsequent value. I have gotten this to work. However, I am only able to see the final 10 values the way I have it set up. I am trying to find a way to store each "k" value before the next iteration begins so that I will have a vector of all the values. I have it set up for 32 iterations, but eventually need about 7000 so an automatic process is necessary. Here is my code:

[k10]=input('Enter the value of intial k-10: ');
[k9]=input('Enter the value of initial k-9: ');
[k8]=input('Enter the value of initial k-8: ');
[k7]=input('Enter the value of initial k-7: ');
[k6]=input('Enter the value of initial k-6: ');
[k5]=input('Enter the value of initial k-5: ');
[k4]=input('Enter the value of initial k-4: ');
[k3]=input('Enter the value of initial k-3: ');
[k2]=input('Enter the value of initial k-2: ');
[k1]=input('Enter the value of initial k-1: ');

%k1-k10 represent the initial condition the 10 chips used to construct
%different PRN numbers.
%For PRN 22: k10=1, k9=1, k8=0, k7=0, k6=1, k5=1, k4=1, k3=1, k2=1, k1=1
%For PRN 27: k10=0, k9=0, k8=1, k7=1, k6=1, k5=1, k4=1, k3=1, k2=1, k1=1

N=32;
count=1;

%N is the maximum number of iterations requested and counts each iteration
%in increments of 1.

while count<=N

if k6+k9==1
k=1;
elseif k6+k9==2
k=0;
elseif k6+k9==0
k=0;
end
%This if-else statement resolves the modulo-2 arithmetic requirement for
%the PRN generator.

k10=k9;
k9=k8;
k8=k7;
k7=k6;
k6=k5;
k5=k4;
k4=k3;
k3=k2;
k2=k1;
k1=k;

%The above equalities represent the Linear Feedback Shift Register. Note
%that, after each iteration, the values shift from a position of k-j to a
%position of k-j-1 until the value falls off after the k-10 position.

count=count+1;

%count=count+1 moves each moves the count to the next iteration, ending at
%N iterations.

end

Thanks for any help. This is killing me.
 
Physics news on Phys.org
  • #2
Apologies: This is in MATLAB
 
  • #3
Make an array for each k1/2/3/.../10 to hold all of the values and change your loop so as you iterate from 1:N you go through different columns of k1/2/.../10.

For ex.
N=32;
count=1;

k10 = zeros(1,N)
K10(1) = input('Enter the value of intial k-10: ');

while count<=N

% Check current column
if k6(count)+k9(count)==1
k=1;
...

% Update the next column
k10(count + 1)=k9(count);
...

end
 
  • #4
I see what you are doing there. I have been looking at arrays but tried to implement them all wrong at the end. I remade the code with the arrays as a part of every variable. It now looks like this:

N=32;
count=1;

k10=zeros(1,N);
k10(1)=1;
k9=zeros(1,N);
k9(1)=1;
k8=zeros(1,N);
k8(1)=0;
k7=zeros(1,N);
k7(1)=0;
k6=zeros(1,N);
k6(1)=1;
k5=zeros(1,N);
k5(1)=1;
k4=zeros(1,N);
k4(1)=1;
k3=zeros(1,N);
k3(1)=1;
k2=zeros(1,N);
k2(1)=1;
k1=zeros(1,N);
k1(1)=1;

while count<=N

%check current column
if k6(count)+k9(count)==1
k=1;
elseif k6(count)+k9(count)==0
k=0;
elseif k6(count)+k9(count)==2
k=0;
end

%update the next column
k10(count+1)=k9(count);
k9(count+1)=k8(count);
k8(count+1)=k7(count);
k7(count+1)=k6(count);
k6(count+1)=k5(count);
k5(count+1)=k4(count);
k4(count+1)=k3(count);
k3(count+1)=k2(count);
k2(count+1)=k1(count);
k1(count+1)=k;

end

I tried to run it with N=32 and it said busy for a long time. Is creating this many arrays going to bog down the system or did I do something wrong?
 
  • #5
nevermind. Forgot the count=count+1

Thank you for the help.
 

1. Why is it important to save values after each iteration?

Saving values after each iteration allows for easy retrieval and analysis of data. It also ensures that any progress made during the iteration is not lost in case of unexpected errors or interruptions.

2. What is the best way to save values after each iteration?

The best way to save values after each iteration depends on the programming language and environment being used. Some common methods include creating a data structure, such as an array or list, to store the values or writing them to a file.

3. Can saving values after each iteration slow down the program?

Yes, saving values after each iteration can potentially slow down the program depending on the amount and complexity of data being saved. However, it is often a necessary step for accurate data analysis and the performance impact can be minimized through efficient coding practices.

4. Is it possible to save values after each iteration without using additional memory?

In most cases, it is not possible to save values after each iteration without using additional memory. However, some programming languages and techniques, such as streaming data, can help reduce the amount of memory needed for storing values.

5. How do I access the saved values after each iteration?

The saved values can be accessed by referencing the data structure or file where they were saved. This can be done within the code or by importing the data into a separate analysis tool. It is important to ensure that the saved values are properly organized and labeled for easy retrieval.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Linear and Abstract Algebra
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
2
Replies
36
Views
3K
Replies
5
Views
365
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
15
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Atomic and Condensed Matter
Replies
3
Views
874
Back
Top