Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

why this prog is not working properly??

1 Ansicht (letzte 30 Tage)
mary
mary am 29 Jan. 2013
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
L=10;
a=1/(2^(1/2));
arr=[0 0 0 0 0 0 0 0 0 1 0;0 1 0 0 1 0 0 1 0 0 1;1 0 0 0 0 0 1 0 0 -1 0;1 1 0 0 1 0 1 1 0 0 -1;0 0 0 1 0 0 0 1 0 0 1;0 1 0 1 1 0 0 0 0 1 0;1 0 0 1 0 0 1 1 0 0 -1;1 1 0 1 1 0 1 0 0 -1 0;0 0 1 0 0 1 0 0 1 a a;0 1 1 0 1 1 0 1 1 -a a;1 0 1 0 0 1 1 0 1 -a -a;1 1 1 0 1 1 1 1 1 a -a;0 0 1 1 0 1 0 1 1 -a a;0 1 1 1 1 1 0 0 1 a a;1 0 1 1 0 1 1 1 1 a -a;1 1 1 1 1 1 1 0 1 -a -a];
nstate1=0;
nstate2=0;
for h=1:L
input=randi(2,1,2)-1;
pstate1=nstate1;
pstate2=nstate2;
for i=1:16
if (arr(i,1)==input(1,1)) && (arr(i,2)==input(1,2)) && (arr(i,3)==pstate1) && (arr(i,4)==pstate2)
ii = i;
end
end
nstate1=arr(ii,5);
nstate2=arr(ii,6);
sireal(h)=arr(ii,10);
siimag(h)=arr(ii,11);
si(h)=complex(sireal(h),siimag(h));
end
the values of si should be an array of 10 complex values .. but when i run it i didn't get those values!!
  4 Kommentare
Cedric
Cedric am 29 Jan. 2013
Bearbeitet: Cedric am 29 Jan. 2013
If you get no answer, I would say that it would be a good occasion for learning how to execute your code step by step.
Place your cursor on the row " nstate1=0; " anywhere, press F12 for creating a break point (indicated by a large red dot), then press F5. You see that a green cursor appeared where your break point was set, indicating that your code was run until this point. If you have MATLAB R2012, a tab with debugging options for stepping in/out/to cursor also appeared. On former versions, you find them in a menu called Debug. The command line prompt is now K>>, which indicates that you are in the debugger. You could stop it by pressing shift+F5, but don't do it now. Passing your cursor above variables that were defined above the break point shows their content; you can also type their name on the command line to display them. Now you can move forward in the execution of your code by pressing F10 or F11. F10 executes functions without stepping in, and F11 steps in (you'll have to try both to see the difference once you have a code that calls functions). If you wanted to move after the for loop, you could set a second break point right after the end of the loop and press F5 (which executes the code until the next break point). As mentioned, there are several additional features, like run to cursor, etc. You'll have to play a little with these things to get familiar.
Knowing that, you can easily execute your code step by step and see if what is done is what you expected.
Jan
Jan am 30 Jan. 2013
@Cedric: This is a valid and good answer already. +1 for your comment.

Antworten (0)

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by