About matlab and printing - printf

Anyone out there whom could help me understand this in matlab:
I have a struct for a person:
struct(name, bob,
birth,[1x1struct],
number,35167854)
Where birth is:
struct(day, 20,
month, 5,
year, 1990,)
Now have a function that can take in date of birth and it prints out(called "print_date"); 20.5.1990
But then I want a function that prints out the entire person(name, birth, number). So I made a function which goes
fprintf('%d, %d, %d\n',person.name, print_date(person.date_of_birth), person.number)
But I only get the error message: "too many output arguments".
Could anyone be as kind as to help me out here?

print_date is not provided nor are the types of data in this struct fully clear, but the %d format option is for decimal formatting. Do you really mean to be formatting person.name and the result of print_date as decimals? I cannot say for sure without seeing your code whether person.name is a number, but it does not seem likely.
Try formatting them as %s

Related

How do I get the right date format after using get text on the folder date?

I have tried everything that I can think of to get the right date format. Can anybody help with this RPA-problem in UiPath. I have used the 'get text' activity to get the folder date and after that tried to use the
Datetime.ParseExact(Str variable,"dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture).
It gives me the error:
Assign: String was not recognized as a valid DateTime.
Your help is much appreciated.
edit: I have now sought help from a friend who figured it out. The error was in the string, which could not be seen, because there was an invisible character in the string that I extracted through 'get text' activity. The solution is in 2 steps:
assign another variable to the exact same date and use an if statement to find out if these two strings are equal and you will find out that they are not.
Now use a regex to capture only digits and slash/hyphen which will get rid of the invisible character.
Try to use "dd_MM_yyyy" instead of "dd/MM/yyyy".
The reason is because UiPath/VB.Net has a habit of using US date formatting even though you're using Culture Info...It's a real pain
Try this:
pDateString = "21/02/2020"
Assign a Date type variable = Date.ParseExact(pDateString,"dd/MM/yyyy",nothing)
Here we're telling the parser to use English format date...The Date type returned will be in US format but you can simply convert back to uk IF needed by using something like:
pDateString("dd/MM/yyyy")

Enter date into function without quotes, return date

I'm trying to write a function of this form:
Function cont(requestdate As Date)
cont = requestdate
End Function
Unfortunately, when I enter =cont(12/12/2012) into a cell, I do not get my date back. I get a very small number, which I think equals 12 divided by 12 divided by 2012. How can I get this to give me back the date? I do not want the user to have to enter =cont("12/12/2012").
I've attempted to google for an answer, unfortunately, I have not found anything helpful. Please let me know if my vocabulary is correct.
Let's say my user pulled a report with 3 columns, a, b and c. a has beginning of quarter balances, b has end of quarter balances and c has a first and last name. I want my user to put in column d: =cont(a1,b1,c1,12/12/2012) and make it create something like:
BOQ IS 1200, EOQ IS 1300, NAME IS EDDARD STARK, DATE IS 12/12/2012
So we could load this into a database. I apologize for the lack of info the first time around. To be honest, this function wouldn't save me a ton of time. I'm just trying to learn VBA, and thought this would be a good exercise... Then I got stuck.
Hard to tell what you are really trying to accomplish.
Function cont(requestdate As String) As String
cont = Format(Replace(requestdate, ".", "/"), "'mm_dd_YYYY")
End Function
This code will take a string that Excel does not recognize as a number e.g. 12.12.12 and formats it (about the only useful thing I can think of for this UDF) and return it as a string (that is not a number or date) to a cell that is formatted as text.
You can get as fancy as you like in processing the string entered and formatting the string returned - just that BOTH can never be a number or a date (or anything else Excel recognizes.)
There is no way to do exactly what you're trying to do. I will try to explain why.
You might think that because your function requires a Date argument, that this somehow forces or should force that 12/12/2012 to be treated as a Date. And it is treated as a Date — but only after it's evaluated (only if the evaluated expression cannot be interpreted as a Date, then you will get an error).
Why does Excel evaluate this before the function receives it?
Without requiring string qualifiers, how could the application possibly know what type of data you intended, or whether you intended for that to be evaluated? It could not possibly know, so there would be chaos.
Perhaps this is best illustrated by example. Using your function:
=Cont(1/1/0000) should raise an error.
Or consider a very simple formula:
=1/2
Should this formula return .5 (double) or January 2 (date) or should it return "1/2" (string literal)? Ultimately, it has to do one of these, and do that one thing consistently, and the one thing that Excel will do in this case is to evaluate the expression.
TL;DR
Your problem is that unqualified expression will be evaluated before being passed, and this is done to avoid confusion or ambiguity (per examples).
Here is my method for allowing quick date entry into a User Defined Function without wrapping the date in quotes:
Function cont(requestdate As Double) As Date
cont = CDate((Mid(Application.Caller.Formula, 7, 10)))
End Function
The UDF call lines up with the OP's initial request:
=cont(12/12/2012)
I believe that this method would adapt just fine for the OP's more complex ask, but suggest moving the date to the beginning of the call:
=cont(12/12/2012,a1,b1,c1)
I fully expect that this method can be optimized for both speed and flexibility. Working on a project now that might require me to further dig into the speed piece, but it suits my needs in the meantime. Will update if anything useful turns up.
Brief Explanation
Application.Caller returns a Range containing the cell that called the UDF. (See Caveat #2)
Mid returns part of a string (the formula from the range that called the UDF in this case) starting at the specified character count (7) of the specified length (10).
CDate may not actually be necessary, but forces the value into date format if possible.
Caveats
This does require use of the full dd/mm/yyyy (1/1/2012 would fail) but pleasantly still works with my preferred yyyy/mm/dd format as well as covering some other delimiters. dd-mm-yyyy or dd+mm+yyyy would work, but dd.mm.yyyy will not because excel does not recognize it as a valid number.
Additional work would be necessary for this to function as part of a multi-cell array formula because Application.Caller returns a range containing all of the associated cells in that case.
There is no error handling, and =cont(123) or =cont(derp) (basically anything not dd/mm/yyy) will naturally fail.
Disclaimers
A quick note to the folks who are questioning the wisdom of a UDF here: I've got a big grid of items and their associated tasks. With no arguments, my UDF calculates due dates based on a number of item and task parameters. When the optional date is included, the UDF returns a delta between the actual date and what was calculated. I use this delta to monitor and calibrate my calculated due dates.
All of this can absolutely be performed without the UDF, but bulk entry would be considerably more challenging to say the least.
Removing the need for quotes sets my data entry up such that loading =cont( into the clipboard allows my left hand to F2/ctrl-v/tab while my right hand furiously enters dates on the numpad without need to frequently (and awkwardly) shift left-hand position for a shift+'.

Format-Specifiers Syntax Error?

i am having a little trouble with printf specifiers...so before asking you guys i read almost everything onC++Reference page, but couldnt fix the problem, and since i am new at c i cant even understand the problem, its most likely a syntax error but i can't find it...
for(i = 1; i <= 10; i++) {
printf("\n%d.%s%n",i,names[i-1],offset);
printf("%*s%.2f TL",10-offset," ",prices[i-1]);
}
so basically i have this code to print a list, and i want the prices to start from the same column.
For e.g:
water 1.00
oj 1.00
and the logic behind my code (incase it's not obvious, i can't tell if it is) is:
print id number and name, count how many chars we've written so far and assign it to offset.
print (starting column of price list)-offset spaces before price
once i couldn't get the result i want, i checked and found out that offset is 3 for all names which is not the case(and no value is assigned to offset before this procedure).
Thanks for any kind of help !
PS: This is a practice code just to get better at using specifiers efficiently.
edit:
so i did this :
for(i=1;i<=10;i++)
{
printf("%d.%s%n",i,names[i-1],&offset);
printf("%*s%.2f TL\n",10-offset," ",prices[i-1]);
}
but what i get as a result is huge empty black command screen.
The %n format specifier requires a pointer. Your code is missing the & operator for offset:
printf("\n%d.%s%n",i,names[i-1],&offset);
The good ol' C interface doesn't know what types you supply to printf so it doesn't complain and happily reads the 4 byte integer value of offset on the stack as a memory location -> core dump.
Actually, g++ with -Wall does warn. So
hd1 has a point here because C++ output is type safe (even though it's a pain);
Heed thy warnings.
When you use %n in a printf format, the corresponding parameter must be a pointer. printf will store the information in the int you point it to.
Assuming you've declared int offset somewhere, you should use &offset as the last argument in your printf call.
While we're here, allow me to comment on this excerpt:
printf("\n
ARGH NO! Newline is a terminator. It goes at the end of a line, not the beginning.
so i did this :
for(i=1;i<=10;i++)
{
printf("%d.%s%n",i,names[i-1],&offset);
printf("%*s%.2f TL\n",10-offset," ",prices[i-1]);
}
but what i get as a result is huge empty black command screen.
edit: Can you guys try this and tell me if you get normal results? I can't understand the mistake occuring, so i can't get past it...Maybe some other examples will lead me to where is the mistake.

ms-access built in function Month(number)

I Have been playing with variations of the Month... function in access query builder. I am having trouble building a date value from an expression. I am looking to create my own date that will be behind the scenes to perform some filtering and other tasks. My problem is that I cant seem to get the Month(number) function to do what I think it should be doing. Here is a summary of what I am looking for.
5/31/2012
Through something like this
DateSerial(Year(Date()),Month(5),Day(31))
Also
DateSerial(Year(Date()),Month("5"),Day("31"))
When I try these as an experssion the return is
1/30/2012
Im sure I am misunderstanding the structure. Please educate me.
DateSerial requires three integers, year, month, day:
DateSerial(1992,5,2)
02/05/1992 ''Euro locale
Year(Date()) returns an integer, so you can substitute:
DateSerial(Year(Date()),5,31)
Interestingly, the zeroth day is the last day of the previous month:
DateSerial(2012,12,0)=30/11/2012
-- http://office.microsoft.com/en-ie/access-help/HV080206953.aspx
As an aside, do not forget that all dates are numbers.
Month(5) will equal 1, but Month(41263)=12 !
Also
?month(100)
4
?Year(100)
1900

Reporting Services - handling an empty date?

Hey, I have a report parameter which looks like this: 01.01.2009 00:00:00
Its a date (as string), as you might have guessed :). The problem is, this param can be an empty string as well. So I tried those expressions:
=IIf(IsDate(Parameters!DateTo.Value), CDate(Parameters!DateTo.Value), "")
=IIf(Len(Parameters!DateTo.Value) > 0, CDate(Parameters!DateTo.Value), "")
Both dont work and the value for the textfield where I print the expressions result is always #Error. As soon as I remove the CDate stuff, it works, but I have to use it. IS there another way to achieve that? What I want is to display nothing if its not a date or the date (format dd.mm.yyyy) if its a date.
Ideas?
Thanks :)
All arguments to the IIf are evaluated, which results in your error, since the CDate will fail for an empty string.
You can get around this by just writting a function along these lines, using a standard if statement:
Function FormatDate(ByVal s As String) As String
If (s <> "") Then
Return CDate(s).ToString()
Else
Return ""
End If
End Function
Then call it with: =Code.FormatDate(Parameters!DateTo.Value)
First, fix your database to properly store dates rather than doing these workarounds. You probably have bad data in there as well (Feb 30 2010 for example or my favorite, ASAP). Truly there is no excuse for not fixing this at the database level where it needs to be fixed except if this is vendor provided software that you can't change (I would yell at them though, well notify them really, and ask them to fix their data model or go to a new product designed by someone who knows what they are doing. A vendor who can't use dates properly is likely to have software that is very poor all around).
In the query that you use to select the infomation, have you considered just converting all non-dates to null?