Invalid field name in matlab - matlab

I have a function that takes in the personalia of a person
function person = prompt_person ()
name = input ( ' Whats your name ? ' , 's' ) ;
day = input ( ' What day of the month were you born ? ') ;
month = input (' What month were you born ? ') ;
year = input ( ' What year were you born? ') ;
phone = input ( ' Whats your telephone number ? ') ;
date_of_birth = struct ('day', day, 'month', month, 'year', year) ;
person = struct ( 'name' , name, 'date_of_birth' , date_of_birth , 'phone' , phone ) ;
end
But I keep getting the error message "Invalid field name "name" ", "Error message in prompt_person (line 8) And I have no idea whats wrong because I've tried creating a simpler little test function:
function [out] = tes( )
word=input('Insert word here ','s');
num=input('Insert number here ');
out= struct('Number1', word, 'Number2', num);
end
And it works just fine, even though it seems to be the exact same code which gets me in toruble in the first function. Any ideas what's going on here?

I tried changing the variable name to personName as suggested and I accidentaly found out whats wrong:
Turn out I needed to use a variable name with no space between the '' and the text.
E.g. 'PersonName' instead of ' PersonName '.

You might consider using strtrim to strip leading and trailing whitespeace from a string. For example:
>> name = ' John Doe ';
>> name = strtrim(name)
name =
John Doe
If you need to remove all spaces, try strrep(name,' ','').
>> name = strrep(name,' ','')
name =
JohnDoe

Related

Why is this Calculation not giving me a resulte

I created an ExecuteSQL Calculation:
ExecuteSQL ( "SELECT BaseRent FROM obj_Unit_CurrentRenter_RentAmount WHERE RenterUnitID = ? AND CurRent = 1" ; "," ; ""; RenterUnitID)
I've verified that is works when I take out the AND CurRent = 1 clause. However, with that part in it, the calculation returns a ?.
CurRent is a Number field.
The problem is that your field name CurRent collides with the reserved word CURRENT.
Change your formula to:
ExecuteSQL ( "SELECT BaseRent FROM obj_Unit_CurrentRenter_RentAmount WHERE RenterUnitID = ? AND \"CurRent\" = 1" ; "," ; ""; RenterUnitID)

Concatenating strings Zybooks Lab 2.1.2

Write two statements to read in values for my_city followed by my_state. Do not provide a
prompt. Assign log_entry with current_time, my_city, and my_state. Values should be separated
by a space. Sample output for given program if my_city is Houston and my_state is Texas:
2014-07-26 02:12:18: Houston Texas
Note: Do not write a prompt for the input values.
current_time = '2014-07-26 02:12:18:'
my_city = ''
my_state = ''
log_entry =
''' Your solution goes here '''
print(log_entry)
I've tried several solutions and it is only printing out the date and time. Since the date and
time is given, I figured to concatenate the city and state strings then add them under log
entry however it still only prints out the date. I can't enter the actual city and state
because there is a back end test where Zybooks add a different city and state. Here is what I
have tried so far.
concatenated_string = my_city + ' ' + my_state
log_entry = current_time + concatenated_string
Actually figured it out.
my_city = input("")
my_state = input("")
log_entry = (current_time + ' ' + my_city + ' ' + my_state)

Trying to extract text using CHARINDEX ()- 1 but getting an error

I have a column with Names, and I am trying to split the column into First and Last Name using Text functions such as LEFT/SUBSTRING/CHARINDEX.
Data in the column:
Name
Yang, Jon
Huang, Eugene
Torres, Ruben
Zhu, Christy
Johnson, Elizabeth
Everything works fine as long as I use this code:
SELECT
[Name]
--,LEFT([Name], CHARINDEX(' ', [Name])) AS FirstName
,SUBSTRING([Name], 1, CHARINDEX(' ', [Name] )) AS FirstName
FROM
DataModeling.Customer
But the problem arises when I try to subtract 1 from CHARINDEX to exclude the Comma from the result and it throws this error:
I have done this operation many times in Excel so trying to replicate it with TSQL. Any suggestion on what I am doing wrong is helpful.
You get that error when CHARINDEX(' ', [Name] ) return 0. So minus 1 will make it negative and it is invalid value for substring()
You can use CASE expression to check the return value from CHARINDEX() and return the correct value to substring()
Or, you can "cheat" by using
CHARINDEX( ' ', [Name] + ' ' )
So CHARINDEX() will always return a value that is more than 0

FileMaker Pro 12 - Using Commas As Separators For Address Export

FMP12
I need to use commas to separate data from customer addresses. The address is imported into a notes field like this: "1234 East Palm Ave, Berkeley, Ca 94150".
My script needs to recognize if the street name is 2 or 3 words, and if the city name is 1 or 2 words. The info gets broken up into a couple different Set Variables $streetName, $CityName, $ZipCode, and exported to create a new customer profile.
I was trying to do that with a string search function that finds the position of the first and second instand of each "," but my function isn't working. Any hints about which function to use would be greatly appreciated.
Assuming the formatting is consistent, try:
$streetName =
Let (
tokens = Substitute ( Address ; ", " ; ¶ )
;
GetValue ( tokens ; 1 )
)
$cityName =
Let (
tokens = Substitute ( Address ; ", " ; ¶ )
;
GetValue ( tokens ; 2 )
)
$zipCode =
RightWords ( Address ; 1 )

Coldfusion return query based on calculated age

I've got one site in ColdFusion where the client now wants to get a list of certain users who are over a particular age. Here's my code so far:
<cfset minRefAge = 21 >
<cfquery name="rsReferees" datasource="nbsa">
SELECT ID, userFirstName + ' ' + userLastName AS refName, userTown, userDOB, userAccess
FROM UsersSSO
WHERE (dateDiff("yyyy", userDOB, now() ) => #minRefAge#) AND userAccess = 4
</cfquery>
userDOB is my date of birth field. When I run it, I get the following error:
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
I can't spot the error. Could someone help?
Looks like your greater than or equal to sign is backwards. Other than that, your query looks fine to me.
SELECT ID, userFirstName + ' ' + userLastName AS refName, userTown, userDOB, userAccess
FROM UsersSSO
WHERE (dateDiff("yyyy", userDOB, now() ) >= #minRefAge#)
AND userAccess = 4
You may also need to put the ref age in quotes: '#minRefAge#'