Want to give values to Alphabets and them Calculate them - macros

I have given values to the alphabets in Arabic, but I will give example of English alphabets, as both will work the same way, obviously.
A =1 B=2 and so on...
Now I want the Macro to find all As, Bs etc... in the desired cell and then calculate the numbers.

Related

LibreOffice Calc -- countif based on string length

I'd like to setup a countif function that counts the cells in a range based on the cell string length.
I've tried inserting the formula as an argument to the countif function, but I can't get it to work.
I wanted to compare the length for each cell in the range with a specific lenght defined somewhere else, but I don't know how to reference back the cell in the range.
One of my failed attempts was =COUNTIF($'Delovni list1'.$D$3:$D$102;">2")
given that the cells in the range are formatted as text. But the above doesn't even work if there are numbers in the cells.
My use case is this: I need to count the cells with 1 specific letter and cells which have many characters.
Thank you.
seba
I found this to work:
=COUNTIF($'Delovni list1'.$D$3:$D$102;"[:alnum:]..*")
regards,
seba

printmat function: Decimal and percentage

I am very new to MATLAB. I am sorry if my question is basic. I am using "printmat" function to show some matrices in the command console. For example, printmat(A) and printmat(B), where A = 2.79 and B = 0.45e-7 is a scalar (for the sake of simplicity).
How do I increase the precision arbitrarily to seven decimals? For example: my output looks like 2.7943234 and B = 0.00000004563432.
How do I add a currency (say dollar) figure to the output of printmat?
How do I add a percentage figure (%) to the output of printmat?
Note: The reason I use printmat is that I can name my rows and columns. If you know a better function that can do all above, I would be glad to know.
Regards Mariam. From what I understand, you would like to display the numbers and show their full precision. I am also newbie, If I may contribute, you could convert the number data to string data (for display purposes) by using the sprintf function.
I am using the variable A=2.7943234 as example. This value will not display the full precision, instead it will display 2.7943. To show all the decimal tails, you could first convert this to string by
a = sprintf('%0.8f',A);
It will set the value a to a string '2.79432340'. The %0.8f means you want it to display 8 decimal tails. For this example,%0.7f is sufficient of course.
Another example: A=0.00000004563432, use %0.14f.
A=0.00000004563432;
a=sprintf('%0.14f $ or %%',A);
the output should be : '0.00000004563432 $ or %'.
You could analyze further in https://www.mathworks.com/help/matlab/ref/sprintf.html
You could try this first. If this does not help to reach your objective, I appreciate some inputs. Thanks.
The printmat function is very obsolete now. I think table objects are its intended successor (and functions such as array2table to convert a matrix to a table of data). Tables allow you to add row and column names and format the columns in different ways. I don't think there's a way to add $ or % to each number, but you can specify the units of each column.
In general, you can also format the display precision using format. Something like this may be what you want:
format long

Matlab function to create duplicate obs based on the value of a string variable

In my dataset, I have a variable which takes values like abc-ABC or abc-def-ABC (i.e., one or more lower-case codes and one upper-case code). I would like to (1) count the number of lower-case codes and capture this no. in a new variable (2) multiply the initial observation by this number (e.g., for abc-def-ABC, I would want 2 obs). Can anyone help?
I don't understand what you want with (2) but... To count the occurrences, can't you just
code = 'abc-def-ABC';
observations = numel(regexp(code, '[a-z]+-'))

Remove commas and decimal places from number field

I am trying to add two zero place holders in front of a field without changing the actual values involved. The field is an order number that is being pulled from MOMs. So right now that fields' formula is {cms.ORDERNO}.
When I try '00'+{cms.ORDERNO} the field displays 001,254.00. How can I remove the decimals and comma so it displays 001254?
The usual trick is to pad with plenty of extra digits on the left and then only take the six you really want from the right. This would handle any order number ranging from 1 to 999999.
right("000000" + totext({cms.ORDERNO}, "0"), 6)
When you don't specify a format string, as you tried, it uses default settings which usually come from Windows. By the way, if I recall correctly cstr() and totext() are equivalent for the most part but totext() has more options.
You should also be able to specify "000000" as the format string to produce the left-padded zeroes. Sadly I don't have Crystal Reports installed or I'd check it out for you to be sure. If this is the case then you probably don't need a formula if you just want to use the formatting options for the field on the canvas. If you do use a formula it's still simple.
totext({cms.ORDERNO}, "000000")
You definitely want to use the Replace formula a few times for this. The formula below converts ORDERNO into string, removes any commas and trailing decimal places, then adds the two zeroes at the beginning:
`00` + REPLACE(REPLACE(CSTR({cms.ORDERNO}),".00",""),",","")
So for example, if cms.ORDERNO is 1,254.00 the output from this formula would be 001254
I know this is older, but better solutions exists and I ran across this same issue. ToText has what you need built right in.
"00" + ToText({cms.ORDERNO}, 0, "")
From the Crystal Documentation:
ToText (x, y, z)
x is a Number or Currency value to be converted into a text string; it
can be a whole or fractional value.
y is a whole number indicating the number of decimal places to carry
the value in x to (This argument is optional.).
z is a single character text string indicating the character to be
used to separate thousands in x. Default is the character specified in
your International or Regional settings control panel. (This argument
is optional.)

Detecting Capital Letter Strings in a Larger String

Is there a nice and clean way to find strings of capital letters of size 2-4 in length within a larger string in matlab. For example, lets say I have a string...
stringy = 'I imagine I could FLY';
Is there a nice way to just extract the FLY portion of the string? Currently I'm using the upper() function to identify all the characters in the string that are upper case like this...
for count = 1:length(stringy)
if upper(stringy(count))==stringy(count)
isupper(count)=1;
else
isupper(count)=0;
end
end
And then, I'm just going through the binary vector and identifying when
there there are 2-4 1's in the row.
This method is working... but I'm wondering if there is a cleaner way
to be doing this... thanks!!!
You can use regular expressions for this. The regular expression [A-Z]{2,4} will search for 2-4 capital letters in a string.
The corresponding matlab function is called regexp.
regexp(string,pattern) returns subindexes into string of all the places it matches pattern.
For your pattern I have two suggestions:
\<[A-Z]{2,4}\>. This searches for whole words that consist of 2-4 capital letters (so it doesn't grab TOUCH below):
stringy = 'I imagine I could FLY and TOUCH THE SKY';
regexp(stringy,'\<[A-Z]{2,4}\>') % returns 19, 33, 37 ('FLY','THE','SKY')
(Edit: Matlab uses \< and \> for word boundaries not the standard \b).
If you have strings where case can be mixed within a word and you want to extract those, try (?<![A-Z])[A-Z]{2,4}(?![A-Z]) (which means "2-4 capital letters that aren't surrounded by capital letters):
stringy = 'I image I could FLYandTouchTHEsky';
% returns 17 and 28 ('FLY', 'THE')
regexp(stringy,'(?<![A-Z])[A-Z]{2,4}(?![A-Z])')
% note '\<[A-Z]{2,4}\>' wouldn't match anything here since it looks for
% *whole words* that consist of 2-4 capital letters only.
% 'FLYandTouchTHEsky' doesn't satisfy this.
Pick the regex based on what behaviour you want to occur.