Matlab - Using special characters in table header - matlab

I have constructed a table with data from a struct and now wish to add custom headers to the columns before exporting the table. I found the following command:
T.Properties.VariableNames{'OldHeader'} = 'NewHeader';
This command however does not allow me to use spaces or special characters for my headers. My table contains the output from processed lab data and I wish to have headers like "Vol. [mL]" and "Conc. [wt%]".
To illustrate using the example from matlab documentation:
S.Name = {'CLARK';'BROWN';'MARTIN'};
S.Gender = {'M';'F';'M'};
S.SystolicBP = [124;122;130];
S.DiastolicBP = [93;80;92];
T = struct2table(S)
T.Properties.VariableNames{'Gender'} = 'Sex';
The above works, but restricts me to normal characters and no spaces. My question is how to change "Gender" to "Vol. [mL]" - if even possible?

As #Jubobs already mentioned in the comment, there are some rules for naming variables that prevent you from choosing the exact name that you want. From the documentation that I found by googling the topic:
A valid variable name starts with a letter, followed by letters,
digits, or underscores. MATLAB® is case sensitive, so A and a are not
the same variable. The maximum length of a variable name is the value
that the namelengthmax command returns.
You cannot define variables with the same names as MATLAB keywords,
such as if or end. For a complete list, run the iskeyword command.
However, I could think of two easy ways to work around this:
Different names, for example you can use the variable name Vol_ml
Store the names in a list, perhaps with an index code like v1 for the first variable name, then you can make v1 the name of the first variable.

Related

RMarkdown syntax within apa_table()

I am not sure if I am overseeing something, maybe there is an easy solution for this already (sorry if this is the case) but so far I haven't found one:
When I am passing a manually created data.frame to apa_table() with row names / column names / values containing RMarkdown syntax, for example "$p$" or "$p > .001$", and try to knit it into a docx file, it will not work and just print it as it is. If I use label_variable(df, p="$p$) it does work ofc as expected, but this is my solution only for column names, not for the other locations within a table. The same also accounts for the note = "$p$" beneath an apa_table().
I am curious if it is possible or if a solution already exists, I'd be thankful for some help on this one!
Best regards and thank you in advance
Mischa
By default, apa_table() escapes characters that are special in LaTeX (e.g., $). You can turn this feature off by specifying escape = FALSE. Moreover, if you want to enable full markdown support for your table body, I recommend to specify format = "pipe", which tells apa_table() to return the table in pandoc's pipe format, which in turn supports markdown.
Consider this table with some markdown commands:
table_content <- data.frame(
"$\\mathit{df}$" = "$\\mathit{df} = 1$"
, b = c("**a**", "*b*")
, check.names = FALSE
)
A full call to apa_table() might then look like the following:
apa_table(
table_content
, escape = FALSE
, format = "pipe"
)
A current limitation to this approach seems to be table notes: pandoc's pipe tables do not seem to support table notes, so using markdown syntax for the table's body while also adding a table note does not seem to work at the same time.

selecting cases based upon first few characters in spss?

i want to select cases with particular first 3 characters.
for example cases with first 3 characters containing "I22".
the length of whole value can vary. e,g "I228" or "I2279" but they have common first three characters "I22"
i usually use compute variable_name= "I228".
but this is tedious as i have to enter all variation of "I22" e.g "I228", "I229" and so on..
it would be much easier if i can just select cases based upon same first 3 characters
you can use the char.cubstr function to find out what the first three characters are in your string variable. For example:
if char.substr(variable_name,1,3)="I22" keep_this=1.
or:
select cases if char.substr(variable_name,1,3)="I22".

why I can't use capital as the first character of the var in akka cluster distribute data example

I am trying the official example on https://doc.akka.io/docs/akka/current/distributed-data.html#using-the-replicator
(The first scala example on this page)
But it seems strange when I change my code a little bit.
I record a video what I change in the code .The only change I made is the name of the variable on line 16.From DataKey to dataKey. I just renamed it.
https://photos.app.goo.gl/CZrnNZlW85e9MaF73
Now the question is why it happened.
I can't use capital as the first character of the var in this example ???
Please help me to figure that out.Thanks very much.
Akka Version:2.5.9
Scala Version:2.11.12
IDE:IntelliJ IDEA 2017.3.3 Community Edition
Regarding the pattern matching with #, the # allows you to deal with the object itself after the match. In your example, you check for the variable c, if that variable is an object Changed(DataKey) then you retrieve the DataKey through the method get on the object itself
case c # Changed(DataKey) ⇒
val data = c.get(DataKey)
I finally find the answer to the question!
https://www.safaribooksonline.com/library/view/programming-scala-2nd/9781491950135/ch04.html
There are a few rules and gotchas to keep in mind when writing case clauses. The compiler assumes that a term that starts with a capital letter is a type name, while a term that begins with a lowercase letter is assumed to be the name of a variable that will hold an extracted or matched value.
In case clauses, a term that begins with a lowercase letter is assumed to be the name of a new variable that will hold an extracted value. To refer to a previously defined variable, enclose it in back ticks. Conversely, a term that begins with an uppercase letter is assumed to be a type name.

How to fill a field with spaces until a length in Notepad++

I've prepared a macro in Notepad++ to transform a ldif file in a csv file with a few fields. Everything is OK but I have a final problem: I have to have 2 fields with a specific length and in this moment I cannot ensure that length because in the source file they are not coming so
For instance, I generate this line:
12345,namenamename,123456
And I have to ensure that the 2nd and 3rd fields have 30 (filling with spaces at right side) and 9 (filling with zeros at left) characters, so in this case I should generate:
12345,namenamename ,000123456
I haven't found how Notepad++ could match a pattern in order to add spaces/zeros, so I have though in to add 1 space/zero to the proper field and repeat this step so many times as needed to ensure the lengths (this is, 29 and 8, because they cannot come empty) and search with the length in the regex (for instance: \d{1,8} for the third field)
My question is: can I repeat only one step of the macro several times (and the rest of the macro only 1 repetition)?
I've read the wiki related to this point (http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Editing_Configuration_Files#.3CMacros.3E) and I don't found anything neither
If not possible, how could be a good solution? Create another 2 different macros and after execute the main one, execute this new 2 macros several times?
Thanks in advance!
A two pass solution with Notepad++ is possible. Find a pair of characters or two short sequence of characters that never occurs in your data file. I will use =#<= and =>#= here.
First pass, generate or convert the input text into the form 12345,=#<=namenamename______________________________,000000000123456=>#=. Ie add 30 spaces after the name and nine zeroes before the number (underscores used here just to make things clearer).
Second pass, do a regular expression search for =#<=(.{30})_*,0*(\d{9})=>#= and replace with \1,\2.
I have just suggested a similar solution in special timestamp format of csv

Strip excess padding from a string

I asked a question earlier today and got a really quick answer from llbrink. I really should have asked that question before I spent several hours trying to find an answer.
So - here's another question that I have never found an answer for (although I have created a work-around which seems very cludgy).
My AHK program asks the user for a login name. The program then compares the login name with an existing list of names in a file.
The login name in the file may contain spaces, but there are never spaces at the beginning of the name. When the user enters the name, he may include spaces at the beginning. This means that when my program compares the name with those in the file, it can not find a match (because of the extra spaces).
I want to find a way of stripping the spaces from the beginning of the input.
My work-round has been to split the input string into an array (which does ignore leading spaces) and then use the first element of the array. This is my code :
name := DoStrip(name)
DoStrip(xyz) ; strip leading and trailing spaces from string
{
StringSplit, out, xyz, `,, %A_Space%
Return out1
}
This seems to be a very laboured way to do it - is there a better way ?
I don't see a problem with your example if it works on all cases.
There is a much simpler way; just use Autotrim which works like this.
AutoTrim, On ; not required it is on by default
my_variable = %my_variable%
There are also many other different ways to trim string in autohotkey,
which you can combine into something useful.
You can also use #LTrim and #RTrim to remove white spaces at the beginning and at the end of the string.