I am trying get three parameters of x, y, and z from this script but all it does is return one value that is not the dimensions I am looking for? - perl

I am new to perl and i am trying to get the dimensions which i think are given from the GeometricCenter method in this perl script. I used this script and it ran and returned only one value which i believe is a value called the gyration which is a paramter that helps determine the xyz dimensions. I thought this script would of returned the dimensions but it did not. Anyone know?
so i tried printing the values in the array xyz which i thought they were in. I tried this by using say but it said i cannot use say on an undefined value
This is the actual problem.
https://github.com/michal-brylinski/eboxsize/blob/master/eBoxSize-1.1.pl

As far as I can tell, your question boils down to "how do I print the values of an array?".
The answer depends on how you want the results formatted, but in the simple case of space-separated numbers, you can just do
print "#geo_center\n";

Related

How to best print output to command window during a loop in Matlab?

I have a loop which iterates through a list of ID numbers paired with a given stress value. The code works fine, except there is no guarantee that the lists have identical lengths. I currently have an if isempty(stress_value) loop with a continue statement if an ID number doesn't have corresponding stress value. All of this takes place in a for id = 1:num_ids loop.
I am now trying to print this id value (class 'double') to the command line, if it doesn't have an assigned stress value, so if the isempty statement is True, prior to continuing out of the loop. As an example, if I set num_ids equal to 101, but the list I'm iterating through only has ID values 1-100, I want to output this 101 ID to the command line.
I've tried printing as an error like this:
error(['The following ID does not have an assigned stress value: ',id])
Here id simply prints as e however when I try this in the command window, which I don't quite understand. When I run it in the script nothing is printed to the command window.
I have also tried simply adding a display command for the id to the loop as follows, however when I run the code nothing shows up again:
disp(id)
Sorry for the simple question, but I have not found an effective way to do this yet, and would appreciate your feedback!
Check the fprintf. You can format your output just like you want.
for id=1:num_ids
% do something
if isempty(stress_value)
fprintf('The following ID does not have an assigned stress value: %d\n',id)
continue
end
% do something
end
The error function will stop code execution.
The display function only prints the value of the variable, without printing the variable name.

"Not enough input arguments" error using add_line()

I'm trying to use add_line() to organize a link with the 'autorouting' parameter.
Here is my code :
add_line(sprintf('%s',diagrammeName), [pos_array_out{pos_out};pos_array_in{pos_in}], 'autorouting','on');
where pos_array_out is a cell of Output position and pos_array_in is a cell of Input position.
And pos_in and pos_out are indices of cell.
But it returns an error :
Not enough input arguments
Why do I get this error?
add_line() has three mandatory arguments when using name-value pairs: sys, out, and in, and optional name-value pairs. Breaking down your input:
add_line(sprintf('%s',diagrammeName),...
[pos_array_out{pos_out};pos_array_in{pos_in}],...
'autorouting','on'...
);
Directly tells you what the problem is. You have two input variables: 1) sprintf('%s',diagrammeName), 2) [pos_array_out{pos_out};pos_array_in{pos_in}], and the name-value pair ('autorouting','on'). So basically you fed it two of the three mandatory parameters, hence you get the error.
I suspect, due to the way you use your variable names, you should do
add_line(sprintf('%s',diagrammeName),...
pos_array_out{pos_out},...
pos_array_in{pos_in},...
'autorouting','on'...
);
i.e. split the out and in variables as suggested in the documentation.
The other type of input add_line() accepts is h = add_line(sys,points), in which case you have two positional arguments, like you do here, but cannot use name-value pairs apparently. The reason for this is that the former syntax tells you where the line starts and where it ends, and name-value pairs then control what the line looks like, i.e. where the line actually passes (moving around objects). Using sys, points is like doing plot(x,y), it draws a line between pre-specified points. Using a name-value pair to control the shape is then moot, since you already implicitly provide the shape with the points.
Doing [a;b] creates an array, which is a single variable, hence the error.

Why does this line return sum of integers 1-10?

I'd like to understand how unpack is returning the sum in the given perl one-liner.
I've looked at pack man page and mostly understood that it is simply formatting the given array into a scalar of ten doubles.
However, I couldn't find proper documentation for unpack with %123. Looking for help here.
print unpack "%123d*" , pack( "d*", (1..10));
This line correctly outputs 55 which is 1+2+3+...+10.
From perldoc -f unpack:
In addition to fields allowed in pack(), you may prefix a field with a % to indicate that you want a <number>-bit checksum of the items instead of the items themselves.
Thus %123d* means to add all the input integers 1..10 and then take the first 123 bit of this result in order to construct the "<number>-bit checksum". Note that %8d* or just %d* (which is equivalent to %16d*) would suffice too given that the sum is small enough.

How to print variable inside function

I'm using RRDs::Simple function and it needs bunch of parameters.
I have placed these parameters in a special variable (parsing, sorting and calculating data from a file) with all quotes, commas and other stuff.
Of course
RRDs::create ($variable);
doesn't work.
I've glanced through all perl special variables and have found nothing.
How to substitute name of variable for the data that contained in that variable?
At least could you tell me with what kind of tools(maybe another special variables) it can be done?
Assuming I'm understanding what you're asking:
You've build the 'create' data in $variable, and are now trying to use RRDs::create to actually do it?
First step is:
print $variable,"\n"; - to see what is actually there. You should be able to use this from the command line, with rrdtool create. (Which needs a filename, timestep, and some valid DS and RRA parameters)
usually, I'll use an array to pass into RRDs::create:
RRDs::create ( "test.rrd", "-s 300",
"DS:name:GAUGE:600:U:U", )
etc.
If $variable contains this information already, then that should be ok. The way to tell what went wrong is:
if ( RRDs::error ) { print RRDs::error,"\n"; }
It's possible that creating the file is the problem, or that your RRD definitions are invalid for some reason. rrdtool create on command line will tell you, as will RRDs::error;

Error: Can't take log of -9.4351e+0.007

I am creating a mini search engine using Perl.While doing so I am using a formula with log to the base 10. However for some value I am getting an error:
Can't take log of -9.4351e+0.007.
It is impossible to track where I am getting this error from. I just want to ignore this case. How can this be handled in Perl. Subroutine for finding log to the base 10 is like this:
sub log10 {
my $n=shift;
return log($n)/log(10);
}
So probably i am looking for a check which says if so and so value dont find log.
You cannot take the log of negative numbers.
See Wolfram MathWorld for more details.
Apart from the value being negative, the string -9.4351e+0.007 is not a valid number as the exponent part of a floating-point constant can be only an integer.
You must be passing strings to your log10 function as Perl would not complain about a number in this format.
You need to look at the source of these values as something is going wrong before your function is called, and it will probably give you incorrect results even for those values that can be passed to log without error.
"ln y" means "find the x where ex equals y".
e is a positive number (near 2.17828), so no matter how many times you multiply e with itself, you'll never get a negative number.
You cannot find the log of negative numbers.
As Borodin also points out that -9.4351e+0.007 isn't recognized as a number by Perl.
>perl -wE"say 0+'-9.4351e+0.007'"
Argument "-9.4351e+0.007" isn't numeric in addition (+) at -e line 1.
-9.4351