Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
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?
thanks,
relayman357
Solved! Go to Solution.
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:
2. You can rename the Ypos variable inside the program to Yp, if you like. It will not matter:
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
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
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:
2. You can rename the Ypos variable inside the program to Yp, if you like. It will not matter:
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:
One may also consider to shorten it a bit by using an intermediate variable Z:
You're right. I was being quick and dirty.
Luc