"Not enough input arguments" error using add_line() - matlab

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.

Related

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?

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";

writing the input arguments for a function in matlab

I am using this function on matlab
[ProbData,HazData] = cdsbootstrap(ZeroData,MarketData,Settle,[],[],[],[],[],[],0.25)
and it is giving me an error because it dose not understand the [ ].
I want to keep the default inputs from 4-->9 and change the ninth input to 0.25. What should I put instead of the [ ]?
The function cdsbootstrap uses matlab's very common Name/Value pair syntax. Read the first few lines here:
Specify optional comma-separated pairs of Name,Value arguments. Name
is the argument name and Value is the corresponding value. Name must
appear inside single quotes (' '). You can specify several name and
value pair arguments in any order as Name1,Value1,...,NameN,ValueN.
So if you wanted ALL default values, you would use the call:
[ProbData,HazData] = cdsbootstrap(ZeroData,MarketData,Settle);
If you wanted to change one of these possiblities you would simply include the name and value, all names omitted are set to defaults. Based on your value of 0.25 I'm going to assume you are trying to set the RecoveryRate since 0.25 is close to the default.
[ProbData,HazData] = cdsbootstrap(ZeroData,MarketData,Settle,'RecoveryRate',0.25);
Ref:
http://www.mathworks.com/help/fininst/cdsbootstrap.html

read function from text file in matlab

I'm going to read some function from a Unicode text file in matlab and calculate there answer with my own variables. first i use fopen to read the text file, then what should i do to convert each line of that text file to a function? for example the func.txt contains:
(x^2)-3y
sin(x+z)+(y^6)
and i need to write an m.file which read func.txt and process that like this:
function func1[x,y] = (x^2)-3y
function func2[x,y,z] = sin(x+z)+(y^6)
Preamble: if your final aim is to use those functions in matlab (i.e. evaluate them for some values of x,y,...), I would rather suggest the following approach that looks more robust to me.
In principle, in fact, you don't need to manipulate the file funct.txt to evaluate the functions defined therein.
First problem: each line of your file funct.txt must define an inline function.
Say that the first function (i.e., the first line) of the file funct.txt has been copied into a string str,
str = '(x^2)-3y',
you can obtain a function from it using the command inline:
f1 = inline(str,'x','y');
which gives to you (matlab output)
f1 =
Inline function:
f1(x,y) = (x^2)-3y.
Now you can use f1 just calling it as f1(x,y), for whatever values x,y.
Second problem: you have to parse your file funct.txt to obtain the strings str containing the definitions of your functions. That's easier, you may want to consider the function fgets.
Third problem: the functions in funct.txt may depend on 2,3 (or more?) independent variables. As far as I know there is no easy way to parse the string to discover it. Thus, you may want to define each inline function as depending on all your independent variables, i.e.
f1 = inline('(x^2)-3y','x','y','z');
the variable z will play no active role, by the way. Nonetheless, you need to specify a third dummy parameter when you call f1.

arguments of a function in matlab

I am writing a function with two arguments and I want the second argument to be processed as a string. The following code encounters an error
function Derivative = derive ( Matrix9x1 , string Variable )
end
How can I tell it to matlab?
I mean even if the user inputs 1 as the second argument it should be processed as an string
and the user should be able to enter for example omega
The second argument to your function will only be processed 'as a string' if it 'is a string', that is if you enclose it in single quotation marks. If you want to pass a number to a function and turn it into a string for further operations, use the function num2str. If you want to write a function which takes different actions depending on the type of the second argument you're going to have to test that type when the function is called; you might want to look at the functions ischar, isstrprop, isnumeric, and their relations.
Oh, and don't forget that a Matlab 'string' is really an array of characters which are just a convenience 'type' for integers-representing-characters.
Matlab functions are unlike programming language functions. Not that your example in these programming languages will not work either. Passing an integer to a function that expects a string, will give you compilation errors.
The best alternative in Matlab that I can think of will be to check or convert the second input variable inside the function. Maybe this can help you: http://www.mathworks.nl/help/techdoc/ref/typecast.html

Perl autoincrement of string not working as before

I have some code where I am converting some data elements in a flat file. I save the old:new values to a hash which is written to a file at the end of processing. On subsequence execution, I reload into a hash so I can reuse previously converted values on additional data files. I also save the last conversion value so if I encounter an unconverted value, I can assign it a new converted value and add it to the hash.
I had used this code before (back in Feb) on six files with no issues. I have a variable that is set to ZCKL0 (last character is a zero) which is retrieved from a file holding the last used value. I apply the increment operator
...
$data{$olddata} = ++$dataseed;
...
and the resultant value in $dataseed is 1 instead of ZCKL1. The original starting seed value was ZAAA0.
What am I missing here?
Do you use the $dataseed variable in a numeric context in your code?
From perlop:
If you increment a variable that is
numeric, or that has ever been used in
a numeric context, you get a normal
increment. If, however, the variable
has been used in only string contexts
since it was set, and has a value that
is not the empty string and matches
the pattern /^[a-zA-Z][0-9]\z/ , the
increment is done as a string,
preserving each character within its
range.
As prevously mentioned, ++ on strings is "magic" in that it operates differently based on the content of the string and the context in which the string is used.
To illustrate the problem and assuming:
my $s='ZCL0';
then
print ++$s;
will print:
ZCL1
while
$s+=0; print ++$s;
prints
1
NB: In other popular programming languages, the ++ is legal for numeric values only.
Using non-intuitive, "magic" features of Perl is discouraged as they lead to confusing and possibly unsupportable code.
You can write this almost as succinctly without relying on the magic ++ behavior:
s/(\d+)$/ $1 + 1 /e
The e flag makes it an expression substitution.