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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Translate the entire conversation x

Combine two matrixes

Snowshoeman
12-Amethyst

Combine two matrixes

I'm trying to stack two matrixes into a single text file.  Screen shot of what I would like is in the file.  Between the two files is a user defined combination of letters and numbers.  obviously, the top For loop is not working right.

 

There also seems to be an extra space in front of [INFO] in the text file. And there is an undefined character at the end of each line of the top matrix.

 

 

ACCEPTED SOLUTION

Accepted Solutions

That Works!  Thanks!  I get this programming stuff down sometime!

View solution in original post

8 REPLIES 8
Werner_E
25-Diamond I
(To:Snowshoeman)

Actually you are not al all just stacking two matrices. As I understand you only want to use the second column of the first matrix, but both columns of the second one.

Your WRITECUSTOM function is not using the last argument at all, so why do you intend to see it in the file created?

See if the attached does what you intend.

Werner_E_0-1758057046830.png

 

 

That Works!  Thanks!  I get this programming stuff down sometime!

LucMeekes
23-Emerald IV
(To:Snowshoeman)

Try this.

 

Success!
Luc

 

 

Thanks!

Delete the line u<-stack(u,0) in WRITECUSTOM.  That solves your Null character problem.

 

The extra character before [INFO] occurs because you stack strvec(T...) to u before you have defined u.   Unfortunately, despite repeated requests, Mathcad has no empty array and initialises u to 0 (hence the Null).  The solution is to simply delete the unwanted 0 after you've finished processing T.

 

Here's the modified WRITECUSTOM:

 

2025 09 16K .png

 

Do you really need both CR and LF?  Usually, just LF suffices.

 

Here's dummy.txt in Notepad++ after the modification.

 

2025 09 16J .png

 

Stuart

Thank you for your reply.  I was trying not to repeat those 5 top rows five time.

Werner_E
25-Diamond I
(To:Snowshoeman)

As@StuartBruff  wrote he was only correcting the problem with the Null character at the front,

To correct the repeating of the T-values you have to put the  v <-- stack(v,u..) statement outside of the for loop. No need for adding CR LF unless you want an additional empty row at the end of the file.

To correct the missing linefeeds in the M values you have to add linefeeds (or CR & LF).

After doing so, your program also creates the desired file.

Werner_E_0-1758061314133.png

I attach the P11 file with the modifications applied. So you can decide which WRITE function you would prefer. The outcome of both is now identical after I changed my WRITE'EM to just round to 2 decimals rather the former 3.

 

Concerning Stuarts remark about CR LF versus just LF. 

It depends on the operating system. While Windows defaults to CR&LF, Linux and macOS default to just LF.

But most Windows programs are able to handle files where the lines are separated just by LF without CR pretty well and transparently.

So it may suffice even for use with Windows software to just use LF. It also may be the the way to go if the file is to be used on multiple different platforms as especially software running under macOS or Linux may choke on files containing that extra CR.

Thanks!  That gives me a little more to chew on for tomorrow!  I like both presentations.

Announcements

Top Tags