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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

program to parse table data from text file

relayman357
10-Marble

program to parse table data from text file

I have a text file with comma delimited numerical data.  I read it in to the "ld" table and then have a program to parse through and build a matrix from the data (data file attached).  My questions:

 

1) Can I replace the "11" in my for statement with something like "length of (ld)" so my code works when I change the number of rows of data?

 

2) Is there a way to build the Ypos matrix without using the intermediary Yp matrix?  I know Ypos is only defined inside the program - but is there a way to make it "global" or such?

 

3) Is it possible to populate 2 different matrices with 1 program?  So my code would create both a Yp and a second matrix?  If my code creates a Ypos and Yneg how would I pass both of them out?

 

snip.jpg

 

thanks,

relayman357

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:relayman357)

1. As far as mathcad is concerned, ld is a matrix, and supplying it as a parameter to the rows() function works, as my attachment shows. See also here:

LucMeekes_1-1670449434223.pngLucMeekes_2-1670449453744.png

2. You can rename the Ypos variable inside the program to Yp, if you like. It will not matter:

LucMeekes_3-1670449473425.png

What you should realise is that, even if you do that, the internal variable Yp will be different from the Yp (the one encircled green) that you use to carry the result of the program. So I'd say, don't bother.

 

Attached is a corrected version of my previous file. I hadn't realised that you use the first two columns of your ld matrix as indices.

 

Success!
Luc

 

View solution in original post

6 REPLIES 6
LucMeekes
23-Emerald III
(To:relayman357)

1. I see you've found ORIGIN.

You can use the rows(X) function to find the number of rows in a (column) vector or matrix X.

Likewise there's the function cols(X).

But you've defined the variables rows and cols, that may overwrite the function names,

I'm sure you can find a way past that...

Your for loop could look like:

 for r c ORIGIN..ORIGIN+rows(ld)-1

That will make r independent of the actual value of ORIGIN.

 

2. ? I see you build the Yp matrix using the Ypos matrix, not the other way around.

 

3. Your program can return a nested matrix, or a vector of two elements where each element is a matrix:

return [ Ypos Yneg ]

 

The attached file demonstrates one and the other.

 

Success!
Luc

Thanks Luc.

 

1) rows(ld) won't work because ld is a table, not a matrix.  What can I use for a table?

 

2) Sorry, yes, my second question should have been: "Is there a way to build the Yp matrix directly in the program?"   Avoiding the "result Ypos".  

 

Thank you very much.,

relayman357

LucMeekes
23-Emerald III
(To:relayman357)

1. As far as mathcad is concerned, ld is a matrix, and supplying it as a parameter to the rows() function works, as my attachment shows. See also here:

LucMeekes_1-1670449434223.pngLucMeekes_2-1670449453744.png

2. You can rename the Ypos variable inside the program to Yp, if you like. It will not matter:

LucMeekes_3-1670449473425.png

What you should realise is that, even if you do that, the internal variable Yp will be different from the Yp (the one encircled green) that you use to carry the result of the program. So I'd say, don't bother.

 

Attached is a corrected version of my previous file. I hadn't realised that you use the first two columns of your ld matrix as indices.

 

Success!
Luc

 

Nice, thank you Luc.  I forgot that I redefined "rows".  It works as you say now - thank you!

Your modification only works OK if ORIGIN is set to 0. To make your program ORIGIN-aware you'll have to change it slightly:

Werner_E_0-1670451841841.png

One may also consider to shorten it a bit by using an intermediate variable Z:

Werner_E_0-1670452106708.png

 

 

LucMeekes
23-Emerald III
(To:Werner_E)

You're right. I was being quick and dirty.

 

Luc

Top Tags