Skip to main content
13-Aquamarine
September 16, 2025
Solved

Combine two matrixes

  • September 16, 2025
  • 3 replies
  • 875 views

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.

 

 

Best answer by Snowshoeman

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

3 replies

25-Diamond I
September 16, 2025

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

 

 

Snowshoeman13-AquamarineAuthorAnswer
13-Aquamarine
September 16, 2025

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

23-Emerald IV
September 16, 2025

Try this.

 

Success!
Luc

 

 

13-Aquamarine
September 16, 2025

Thanks!

23-Emerald V
September 16, 2025

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

13-Aquamarine
September 16, 2025

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

25-Diamond I
September 16, 2025

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.