Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi Mathcad power users,
A user has a matrix and wants to run some calculations. He wants to step through each row, determine if that row’s data meets a certain requirements, and if yes, return four numbers pertaining to that row. Here’s the kicker. He wants to output those four numbers to a text file with specific (and varying) decimal places. So for example, from a 10x10 matrix, he might want the following result outputted to a text file:
1 0.333 1.4 -0.12345
3 1.222 1.0 0.12345
4 1.211 0.9 -1.00000
9 1.000 0.1 1.00001
So he wants to define the number of decimal places for each column of output.
Can you write a program that will do this?
Mona
Are we allowed to use scripted components?
Does the output file need to look exactly like your example below?
1 0.333 1.4 -0.12345
3 1.222 1.0 0.12345
4 1.211 0.9 -1.00000
9 1.000 0.1 1.00001
Does the program that will read the text file already exist?
Which function will be used to read the text file?
Michael,
Certainly you can use scripted components or any other Mathcad feature.
The output does not have to look like the sample below, that was just an example showing that the user wants to have the output have different numbers of decimals in each column.
The challenge is to choose the function and write the program or suggest options.
Thanks,
Mona
Write to an EXCEL component, use the formatting in the component to set decimals (column by column), and save the EXCEL component as a text file. To automate would take a scripting wizard.
Great! I like the simplicity of your solution.
Thanks,
Mona
Or the like the attached ... (I've only got an early version of Mathcad available at the moment and can't open Wayne's file)
Stuart
You amply demonstrate the difference between a real pro and some schmuck just trying to get something done.
Nice work.
This MC15 worksheet uses the "export to file" feature available for tables by right clicking on the resulting table of the numbers turned into strings. The output file written does not have quotes around the strings, which does occur with other functions (such as WRITEPRN).
The worksheet also contains scriptable objects to 1) re-write the output file to a text file with a file name entered as a variable, and 2) write the table directly to a text file with a file name entered as a variable.
It wasn't really necessary to have the scriptable objects, but I wanted to see if it could be done several ways.
Note that the second script passes the entire table array in Mathcad to the script through a single input variable parameter name. This is a good trick to know since scriptable objects have a maximum of four input parameters allowed. This is a way to overcome that limitation by making an input parameter an array.
I'm very impressed with all 3 solutions. They really demonstrate the power and flexibility of Mathcad.
Are people up for more challenges? If so, I'll see what I can come up with.
Best regards and congratulations to all of you for your creativity,
Mona
Mona Zeftel wrote:
Are people up for more challenges? If so, I'll see what I can come up with
Bring it ON!