Skip to main content
1-Visitor
November 19, 2017
Question

ReadExcel problem

  • November 19, 2017
  • 4 replies
  • 5846 views

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?

4 replies

16-Pearl
November 19, 2017

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. 

23-Emerald IV
November 19, 2017

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

25-Diamond I
November 19, 2017

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

23-Emerald IV
November 19, 2017

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

23-Emerald IV
November 19, 2017

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

23-Emerald IV
November 19, 2017

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!

23-Emerald IV
November 19, 2017

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