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

Defining variables through strings imported from Excel

FraRaff
6-Contributor

Defining variables through strings imported from Excel

Dear all,


As briefly described in the object, I’m looking for a solution that allows to convert a “string name” already defined in an Excel sheet to a variable name into the Mathcad Prime 6.0 doc.

 

Actually, I’m using the READEXCEL function to import string and values that will be used as the inputs for the rest of the Mathcad computation work. With reference to the figure attached, I’m trying to simply associate one-to-one the “meters_var” to the “meters_val”.

 

I think that working with an external input sheet is more robust to the variation of variable names and quantity and relative values, making the approach more automatic since the Excel formats are interfaceable with most of computation programs.

Thanks in advance for your help

ACCEPTED SOLUTION

Accepted Solutions

Attached is a Prime 4.0 Express sheet trying to demonstrate what I was saying above.

 

 

View solution in original post

7 REPLIES 7
FraRaff
6-Contributor
(To:FraRaff)

Sorry, 
here the attached

I assume that you want the items in meters_var to become actual Mathcad variables with the values from meters_val, correct?

 

I believe (without actually seeing it) that in the distant past there was a script that could accomplish that; but you're using Prime and I don't think it supports scripts yet, or no one has written one.  I used to do what you've done and use the array subscripts to track who was who (meters_var4 will return the name while meters_var4 returns the required value).

 

What does work in Prime (sort of) is using tables:

  • Transpose your EXCEL two columns into two rows

Capture.JPG

  • Copy that array in EXCEL and paste it into Prime

Capture1.JPG

  • Some manual editing later, you have what you're after

Capture2.JPG

It's messy, convoluted, time consuming.  If you have a lot of files with the same names you'd only have to do it once; you could read the second, third, etc set of values in once the names have been assigned.

 

Good luck.

 

FraRaff
6-Contributor
(To:Fred_Kohlhepp)

First of all, thanks for your reply.

Yes, I think you pinpoint the matter. But the strategy you used with the array subscripts is not applicable to my goal since the idea is to left the user free to move string and value position in the excel columns. And this is what really happen.

Concerning your suggestion in manipulating rows and arrays in excel, I think that’s what I will do regretfully by creating an excel matrix in Mathcad directly.

It's a shame because we loose the possibility to interface Mathcad with other software and, perhaps, to accomplish an iteration automatically.

Thank you again,
regards

You can pass array notations as arguments to functions.

 

CFFT(meters_val3) works just as well as CFFT(CwT).  So tracking variable by indices is a viable work-around.  (I was importing data from EXCEL files where the names were across the top of the column, and the column was a sampled time history of that parameter.  But the files were not always ordered the same so I had to search the name list for the parameter of interest.)

FraRaff
6-Contributor
(To:Fred_Kohlhepp)

Sorry, I'm not sure I understood your last suggestion.

I tried to implement what you said as in attached. Where I failed? Can you please provide a brief example on how actuate that? I will appreciate a lot.

Thank you so much for you help.
Regards

Attached is a Prime 4.0 Express sheet trying to demonstrate what I was saying above.

 

 

FraRaff
6-Contributor
(To:Fred_Kohlhepp)

Yes, that's exactly what I hoped to do! 

Thank you very much for your help.

Best Regards

Announcements

Top Tags