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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Writing from a matrix challenge

mzeftel
12-Amethyst

Writing from a matrix challenge

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

10 REPLIES 10
MichaelH
12-Amethyst
(To:mzeftel)

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?

mzeftel
12-Amethyst
(To:MichaelH)

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

wayne
12-Amethyst
(To:mzeftel)

Mona

Something like the attached

StuartBruff
23-Emerald III
(To:mzeftel)

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)

wayne
12-Amethyst
(To:StuartBruff)

Stuart

You amply demonstrate the difference between a real pro and some schmuck just trying to get something done.

Nice work.

MichaelH
12-Amethyst
(To:mzeftel)

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.

mzeftel
12-Amethyst
(To:MichaelH)

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

MichaelH
12-Amethyst
(To:mzeftel)

Mona Zeftel wrote:

Are people up for more challenges? If so, I'll see what I can come up with

Bring it ON!

Announcements

Top Tags