Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hello everyone,
I stucked with MathCAD 15. I want to import data from XLS file (geographical coordinates), convert it to some map projection coordinates and finally display on XYplot. I created a function that should create an array for display but there is an error 'This value must be a vector'. This is my first step with MathCAD so an answer could be trivial. Nevertheless, please help me so I could go further. Thank you - Pawel.
PS. I attach MCAD file and input file.
Solved! Go to Solution.
The problem is not the READEXEL command but the format/content of the "empty" cells in the Excel file itself. It looks like those cells are not really empty but contain a null string which is exactly what you also see in the Mathcad matrices (and which are responsible for the error as you can't do mah calculations with strings).
You may give it a try. Doubleclick in Excel into one of the empty cells and press the backspace key. This deletes the content of the cell. Now save the Excel file and let your Mathcad sheet run. You will notice that this specific cell now has a NAN as you expected.
One easy workaround is to use in your function "fun" instead of
if file]i,1 /= NaN
(which does not work that way anyway, you would have to use the negation of IsNaN(file[i,1) )
if file]i,1 = ""
That way no attempt is made to do calculations with strings and the function works.
But ... for every line with an empty string x and y are now 0 (because you don't assign a value). I guess its better to either really skip those lines or at least put NaNs into x,y (which is what I did in the attached sheet.
Other workarounds are to write a function which replaces all empty strings by NaNs in a matrix.
You may use "Match" followed by "trim" to delete all rows of a matrix which contain an empty string.
If you don't like the NaN' in the result of your function "fun" (they interrupt the plotted graph) you may use "filterNaN" to get rid of them (see attached sheet).
You defined L0 with a vector index and later in your program you define a scalar variable L. That way you lose L0 and the scalar L can't be indexed - therefore the error message.
You may want to use the literal index -> L.0
Your program fun just produces a 1x2 matrix, because you overwrite x and y everytime the loops runs.
You probably want to used the vector index x[i and y[i.
Maybe some other variables need to be indexed, too.
With the data you provide the output (just plot one column over the other - see attached file) is just a straight line.
Thank you Werner_E for immediate response. Thanks to you that problem is solved. While I have your attention I would like to ask for one more thing. I uploaded modifed MCAD sheet that uses READEXCEL function. I intended to plot two traces (inputdata and inputdata2). In the second case there are numerous empty records (just timetagging, no positional data). Could you help and tell me how to skip those rows? As you will see I tried your remark to use READEXCEL and insert NaN values. I added if statement to my loop but it didn't help. I have a bunch of files to process and checking every one of them for empty rows woulld take ages. I would be grateful for assistance from such experienced MCAD user like you. PD
The problem is not the READEXEL command but the format/content of the "empty" cells in the Excel file itself. It looks like those cells are not really empty but contain a null string which is exactly what you also see in the Mathcad matrices (and which are responsible for the error as you can't do mah calculations with strings).
You may give it a try. Doubleclick in Excel into one of the empty cells and press the backspace key. This deletes the content of the cell. Now save the Excel file and let your Mathcad sheet run. You will notice that this specific cell now has a NAN as you expected.
One easy workaround is to use in your function "fun" instead of
if file]i,1 /= NaN
(which does not work that way anyway, you would have to use the negation of IsNaN(file[i,1) )
if file]i,1 = ""
That way no attempt is made to do calculations with strings and the function works.
But ... for every line with an empty string x and y are now 0 (because you don't assign a value). I guess its better to either really skip those lines or at least put NaNs into x,y (which is what I did in the attached sheet.
Other workarounds are to write a function which replaces all empty strings by NaNs in a matrix.
You may use "Match" followed by "trim" to delete all rows of a matrix which contain an empty string.
If you don't like the NaN' in the result of your function "fun" (they interrupt the plotted graph) you may use "filterNaN" to get rid of them (see attached sheet).
Werner_E, you are a MCAD five-star general for me, everything is so simple. Thank you very much. Everything works perfectly now. Have a nice day.
Mathccad 15 has a feature missing from Prime you might consider, especially if you're only taking data from a single EXCEL file, You can insert a "data table," and copy the EXCEL data to the clipboard and paste it into the data table. This has the added advantage of storing the data in the Mathcad file. (Now, which EXCEL file did I copy this data from?)
Dear FredKohlhepp,
thank you for your response. Unfortunately I am going to use the procedure on dozens (if not hundreds) of files so the automatization process is crucial here.
Best regards - Pawel