Dev Shed Forums - Beginner Programming http://forums.devshed.com/ Beginner Programming forum discussing problems and solutions for just about any issue. Experienced programmers offer their help to those just starting out. en Tue, 17 Oct 2017 06:33:29 GMT vBulletin 60 http://forums.devshed.com/images/misc/rss.png Dev Shed Forums - Beginner Programming http://forums.devshed.com/ Greatest common divider, Matlab http://forums.devshed.com/beginner-programming/979208-common-divider-matlab-new-post.html Mon, 09 Oct 2017 13:59:09 GMT So, this is a Matlab function to find greatest common divisor with the Euclidean algorithm. Apparently, I missing two rows (where there's percent signs instead) in the end of the function but I can't figure those two rows out. Any help?

Code:

```function [ d ] = GCD_Euclidean( x,y ) if ((x <= 0) || (y <= 0) || (x == y))     d = 0;     disp(['...']);     return end if (y > x)                            a = y;   b = x; else   a = x;   b = y; end                                while (b > 0),                          d = b;                              r = mod(a,b);                      q = (a - r) / b;                    disp(['a = ', num2str(a), ',  b = ', num2str(b) ]);     %     % end end```
]]>
Beginner Programming Nicc http://forums.devshed.com/beginner-programming-16/common-divider-matlab-979208.html
<![CDATA[Script has a side effect I can't resolve]]> http://forums.devshed.com/beginner-programming/979171-script-effect-cant-resolve-new-post.html Fri, 06 Oct 2017 02:53:43 GMT This is really embarrassing. Around the middle of August I posted a script that worked but just barely (http://forums.devshed.com/beginner-programming/977152-bash-file-inefficient-post2979735.html). Rpural was good enough to show me how this could be implemented much more elegantly. Code: --------- #!/bin/bash -x # See if the application in question is running and dump output into a... This is really embarrassing. Around the middle of August I posted a script that worked but just barely. Rpural was good enough to show me how this could be implemented much more elegantly.

Code:

```#!/bin/bash -x # See if the application in question is running and dump output into a text file # GKRELLM=\$(ps aux|grep gkrellm) # instead of using a temporary file, dump the output into a variable # Define some variables representing the ip addresses of the machines I'm testing for # ADAMSMDK=192.168.1.100 PVR=192.168.1.103 SHUTTLE=192.168.1.105 SPIKE=192.168.1.106 check() {         # Check the text file for presence of the ip addresses expected.         # If present, move on, else, open up a gkrellm instance for that ip address.         # Do this for each ip address I'm looking for.         #                                                                                                                                                                            echo \$GKRELLM | grep -Fq "\$1"                                                                                                                                                if [ \$? -eq 0 ]                                                                                                                                                              then echo "found \$1 \$2"                  # If so, move on, if not start a gkrellm instance                                                                                  else ssh -p2222 -f -L 19150:\${1}:19150 \$1 "gkrellm -f -s 127.0.0.1 -P 19150"                                                                                                fi                                                                                                                                                                  }                                                                                                                                                                                                                                                                                                                                                        check \$ADAMSMDK ADAMSMDK                                                                                                                                                    check \$PVR PVR                                                                                                                                                              check \$SHUTTLE SHUTTLE                                                                                                                                                      check \$SPIKE SPIKE```
This works beautifully, but it has a strange side effect. When I run that script it opens gkrellm for the named servers, then it opens a dialog for my password to one of the machines's gkrellm server.

I feed it my password and it opens a second instance of the Gkrellm meter without the expected configuration.

The thing is, for the life of me, I can't figure out what's going on here. Why just that one meter? What's special about that? The configuration for that machine and the Gkrellm server on it is exactly like all the rest, as near as I can tell. I can't even figure out how to troubleshoot this.

Any ideas?