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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

ReadExcel problem

ariperry
3-Visitor

ReadExcel problem

The READEXCEL command on mathcad prime 4.0 will not transfer over my units in excel. How do I make it read my units or how can I add units?

10 REPLIES 10
DJF
16-Pearl
16-Pearl
(To:ariperry)

Excel has no units awareness, so you can't 'read' them in.  You can, however, in mathcad multiply whatever you read in by a unit and it will then have that unit attached.  If you are reading in a few values that's easy. If it's a matrix, then multiply each column or row by the unit.  

  

Same thing writing out to excel - it won't let you send a unit.  So you have to divide everything by the unit you want to get the right numerical value.  

  

Remember - you might be displaying inches or millimeters or whatever - but to mathcad it is stored as the SI unit and only showing you what you ask for.  So, you always have to work appropriately with units.  Temperatures and angle degrees can be particularly tricky.

  

Now, if you had A1 = 5  and B1 = m  in Excel, there might be a way to get mathcad to recognize that B1 is a unit and that A1*B1 = 5m.  But I doubt it. 

LucMeekes
23-Emerald III
(To:ariperry)

Here's an example of the effort requred to get units (from an additional excel column) over to Mathcad:

LM_20171119_ReadExcel.png

As you can see, most of the work is in the GetUnit() function, and it will be a lot of if-statements if you want to be prepared for all possible units...

 

Success!
Luc

Additionally to what Luc had written, you have to be aware that a routine like his GetUnit will only work OK with units of the very same dimension - in case of his exemple units of lengths. A Mathcad function unfortunately is not able to return values of different dimensions depending on an input argument.

Bild.png

LucMeekes
23-Emerald III
(To:Werner_E)

That depends on the version of Mathcad. In Mathcad 11 and before this is not a problem:

LM_20171119_ReadExcelGetUnit.png

This functionality was broken with Static Unit Checking (Mathcad 12?) and it still is impossible in Mathcad 15 if I'm right. In Prime it's possible again:

LM_20171119_ReadExcelGetUnitPrime.png

The problem in Mathcad 11 (and versions before and after) is that you cannot have mixed units in an array. That's possible in Prime too. This is one of the few areas I think where Prime is superior to Mathcad.

 

Success!
Luc

Yes, you are right. It was the introduction of SUC which had broken that behavior in the later version of Mathcad.

We don't know if ariperry is using Prime or Mathcad. If he is using Prime, he indeed could use this solution again.

LucMeekes
23-Emerald III
(To:Werner_E)

He's using Prime 4 (He complains about the READEXCEL function of Prime 4.0 not transferring units...).

 

Luc


@LucMeekes wrote:

He's using Prime 4 (He complains about the READEXCEL function of Prime 4.0 not transferring units...).

 

Luc


Hmm, reading more thoroughly what people are writing really makes things clearer sometimes 🙂

Obvioulsy I was too hasty.

LucMeekes
23-Emerald III
(To:ariperry)

To work seriously with units, you could implement this function in Prime:

LM_20171119_GetUnit.png

You'll need the attached .CSV file with it.

 

Success!
Luc

LucMeekes
23-Emerald III
(To:ariperry)

Ok, Here's the function for Prime (4.0). It works in Express Prime, thanks to the fact that Prime allows mixed units in an array or matrix.

LM_20171119_GetUnitPrime.png

 

Success!

Luc

Corrected, the atto's need to be in between the zepto's and the femto's

The Prime file is corrected.

Also added genuine Omega's, next to Ohms.

 

===> There's an updated version below!

LucMeekes
23-Emerald III
(To:LucMeekes)

Revisited for a more generic solution.

This should cover all SI units.

LM_20171119_GetUnit_1.png

 

The above is to create a UNITS table.

The GetUnit() function definition and a few of its usage examples is below:

LM_20171119_GetUnit_2.png

And the file attached contains the Prime 4 stuff completely.

 

Success!
Luc

Top Tags