cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Translate the entire conversation x

Getting error The value must be scalar or a matrix

JW_9781974
7-Bedrock

Getting error The value must be scalar or a matrix

I am getting error for programming could someone please help 

2 REPLIES 2
Werner_E
25-Diamond I
(To:JW_9781974)

Problem is the unit cm which you add at the end.

If "Len" is larger than 2 cm your program returns the string "n/a" and you can't add a unit to a string. You can add a unit to a scalar numeric value or to a matrix of numeric values, but not to a string - hence the error message.

Werner_E_0-1754996943333.png

BTW, inline evaluation may work OK most of the time but sometimes can lead to unexpected effects. Therefore, I have made it a habit to always separate the definition of a variable and its evaluation/display for safety reasons, as shown in the image above. This also shows clearly that it is not the program that causes the error, but the attempt to display a string with a unit.

 

Solution depends on what you intend to do with a variable which sometimes represents a length and sometimes a string.

 

For example you may replace the string by the built-in constant "NaN" ("Not-a-Number", -> About the NaN (Not a Number) Built-In Constant) or even better for consistency you may add a length unit to NaN, too.

If you need later to programmatically ask if "y" is a numeric quantity or a NaN you may use the boolean function "IsNaN()" because something like "if y=NaN ..." does not work.

Every calculation using y when its NaN will result in NaN, too. Demonstrated below via the simple "Area" function:

The "return" statement is not necessary and also the creation of a program structure (the double bar at the left) could be omitted.

Werner_E_3-1754997753035.png

Calculation of "z" shows that you also could use the if-function (similar to the usual spreadsheet "if") instead of the programmed if-statement.

 

Prime 11 sheet attached

 

Hello @JW_9781974,

 

It looks like you have a response from our community champion. If it helped you solve your question please mark the reply as the Accepted Solution. 
Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.

Thanks,
Vivek N.
Community Moderation Team.

Announcements

Top Tags