Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Hi,
I have some questions about the attached file (questions are highlighted yellow on page 3 & 4). I'm trying to extract columns from my matrices Pz, Px, and My and combine them into new matrices, each with a Pz, Px, and My column, plus zero values for Py, Mx, and Mz.
My first question: why do I lose my units when I convert the nested matrices Pz, Px, and My to regular matrices with the method I used?
Second question - in order from easy to difficult: How do I create one matrix taking the first column from Pz, Px, and My? How to create three matrices with all columns extracted one by one? How to keep the number of matrices flexible in case columns in Px, Pz, and My are removed or added? I'd really like to understand how to do this for future projects as well.
Below an image from Excel on what I'm trying to achieve.
Thank you!
Solved! Go to Solution.
Your function Pz (as well as the others you defined) should not have the sane name as the variable you would like to use as its argument.
Furthermore is your function not using the argument M for its calculation but it uses the worksheet variable Pz and immediately overwrites the argument M with its calculations.
So if you really want to use a function, you should do it that way (I am using the name "R" for the local variable because I am thinking on "Return value" or "Result"):
But if your goal simply is to unravel the nested vector Pz, the most straightforward way would be
You can also avoid the nested structure right away by using the "stack" command
Your function Pz (as well as the others you defined) should not have the sane name as the variable you would like to use as its argument.
Furthermore is your function not using the argument M for its calculation but it uses the worksheet variable Pz and immediately overwrites the argument M with its calculations.
So if you really want to use a function, you should do it that way (I am using the name "R" for the local variable because I am thinking on "Return value" or "Result"):
But if your goal simply is to unravel the nested vector Pz, the most straightforward way would be
You can also avoid the nested structure right away by using the "stack" command
Second question - in order from easy to difficult:
How do I create one matrix taking the first column from Pz, Px, and My?
Unfortunately you can't change the units when displaying a matrix with mixed units.
If your intention is the export to Excel, you would make it unitless anyway:
How to create three matrices with all columns extracted one by one?
How to keep the number of matrices flexible in case columns in Px, Pz, and My are removed or added?
Maybe that way:
According the zero values for Py, Mx and Mz you could use
That looks very much like what I wanted to do. I don't have Prime 9 yet, is there a way to post your sheet in Prime 8 version? Thank you.
And yes, the intent is to export to either Excel or Notepad, so the units do not matter.
Unfortunately provides PTC no way to save or convert a sheet to the format of a lower version.
But actually you see in the pics all you need to retype the few lines.
Furthermore, which is not shown in the pics, I unraveled the three nested matrices Px, Pz and My as I had shown with Pz in a prior reply like this
I used this method because it was easier to do compared to using the stack command right away 😉
To actually see all three matrices when the nested matrix M^T is displayed, you have to turn off the option to collapse nested matrices
To create a separate Excel file for every matrix in M, you could use something like
The assignment to dummy variables is necessary to "trigger" the write command(s).
The Excel files are numbered starting with #1 (independent from the setting of ORIGIN) and look like this
(over here we use the comma as decimal separator)
I was able to unravel the nested matrices with the method you showed. When I use a function to unravel them, I get an error message "this variable is undefined". Do you know why that's happening? Just for my knowledge.
Remove the inline evaluation (The "= ? klf") from the definition of the Pz_f function and it should work.
As a guidance: Avoid using inline evaluation with Mathcad / Prime. Often it works, ever so often it causes problems.
Success!
Luc
As Luc already wrote its the inline evaluation, the "=" after the definition of the function Pz_f().
You would get the very same error if you define " f(x):=sin(x)= ". How should Prime know for which value of x you would like the function to be evaluated?
And I second what Luc said that its usually a good idea to avoid inline evaluations - even if they are used in a legitimate way (as the one at the end of your screen shot.
Thats the reason why I usually use separate regions for the definition and the display of a variable, like in
BTW, I don't think that you need a function like Pz_f() anyway. All thats needed is what is shown here above and thats basically exactly what you did. just not assigned as a function but rather as the new unraveled Pz. I assumed that you won't need the nested structure of the original Pz anymore and so had not chosen a new variable name.
That makes sense, yes. Thanks for all the explanations so far, you guys are amazing resources!
I'll try and work out the Excel file program later today to see if I can make that work.
I remember you can also have MathCad write a file to Notepad.
Does that work in a similar way as the method below?
@Hans_Westerweel wrote:
That makes sense, yes. Thanks for all the explanations so far, you guys are amazing resources!
I'll try and work out the Excel file program later today to see if I can make that work.I remember you can also have MathCad write a file to Notepad.
Does that work in a similar way as the method below?
You may try WRITETEXT(), WRITECSV() or WRITEFILE() instead of WRITEEXCEL().
Look them up in the help for additional arguments you may add.
WRITEPRN() creates an ASCII file, too, but with an added proprietary header, so you probably would have to edit and post-process the file in Notepad.
Unfortunately the header texts will appear in quotes "" in the created ASCII file.
To avoid this and/or to create an ASCII file with a special format to be used as input in another program, it would be necessary to write a elaborate custom output routine in Prime which basically would use WRITEBIN() to write the data.
Thanks again for the elaborate tips! This stuff is going to be so helpful for my job.
I'm having one last issue (almost there). When I export to a text file, some of the columns shift because the output isn't rounded.
I tried rounding it like this, but it says my variable Pz_ is undefined. I feel like I'm not understanding something very basic here about MathCad programming.
Three errors:
Once these errors are corrected, it works as expected
But there is an easier way to achieve the same result using the vectorization operator:
The latter could also be used in the WRITExxx() command, so you can use the exact values in the calculations in the Prime sheet and do not need to define a separate variable just for the export.
For the unit-less export you could also use
Note the lower case "r" in "round".
Otherwise you can of course still use "Round" with the capital "R"