×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how to write multiple vectors to a single file.
2

how to write multiple vectors to a single file.

how to write multiple vectors to a single file.

(OP)
I have four different vectors(column matices) and all of them are different sizes.  I want to export all the vectors to a single file.  I could write only one vector to a file.  Any help is greatly appreciated.

Regards,
Ramesh

RE: how to write multiple vectors to a single file.

All the file output functions can handle matrices, so you simply need to put your vectors into a single matrix

TTFN

RE: how to write multiple vectors to a single file.

(OP)
IRstuff,

I created a matrix with all the four vectors and tried to output the matrix.  But all I can get is the four dashes ( one dash each in 1st cell of four rows).  If you can give some examples, I appreciate it.

Regards,
Ramesh

RE: how to write multiple vectors to a single file.

what function did you use and how did you use it?

TTFN

RE: how to write multiple vectors to a single file.

(OP)
IRstuff,

I have four column matrices viz., u, v , x and y.  They are calculated by set of equations.  u and v are same size and x and y are same size.  

I used the following:
A:=(u,v,x,y)

I used two different ways to export this matrix to a file.

method 1: writeprn(outfile):=A

method 2: From INSERT menu choose COMPONENT
          Select File Write and followed the prompts.

Both methods did not work.

First of all, matrix A just shows that first elements in four colums as column matrix and does not expand.  

I was wondering whether there is any append method which I can use.  

If you have an answer, please post it.

Thanks

RE: how to write multiple vectors to a single file.

It doesn't work because you created a vector with nested vectors, NOT a matrix.

The brute force approach is:
A[i,0:u[i
A[i,1:v[i, etc

Then writeprn(filename):A

TTFN

RE: how to write multiple vectors to a single file.

(OP)
IRstuff,

Thanks for the tip

RE: how to write multiple vectors to a single file.

A much easier way would be to use the augment() function.

Say you had column vectors w, x, y, and z, then you can place them side-by-side into an array with the command:

A:augment(w,x,y,z)

(the : symbol places the = assignment operator there)

Then just writeprn(filename):A as before.

You can also use the stack() command to place column vectors end-to-end.

Hope that helps,
Matt

RE: how to write multiple vectors to a single file.

(OP)
Matt,
Thanks for easy step.  The one problem I have is that not all column vectors are same size. Is there anyway to augment unequal size vectors?  Also is there anymethod to add some comments and variables to the matrix?  (Basically, I am trying to create a output file with comments, input variables and output values in a spread sheet.)

Thanks for your help

Ramesh

RE: how to write multiple vectors to a single file.

Hi Ramesh,

I think your best bet is to use an Excel Component.

Insert>Component...

Select "Microsoft Excel".  Then tell it to make an empty Excel worksheet.

If you have 3 columns vectors (they can be unequal in length), then make 3 inputs and 0 output.  Start the first input at A1, the second input at B1, and the third input at C1.  Tell it that you want 0 ouputs. And click Finish.

Then in the three placeholders under the Excel worksheet, type the variable names of your column vectors.

The Excel worksheet should contain your data now. :)

You can even double click on the object and directly edit the worksheet just as if you were working directly in Excel.   You can also save the worksheet to a file.

Also, it is possible to make an array of strings and specify this as an input to the Excel worksheet object. (At least in Mathcad 11, which is the only version I have access to to test it in.)

Hope that helps!  Good luck!
Matt


RE: how to write multiple vectors to a single file.

(OP)
Matt,

I used that in my program.  But only problem with that I cannot save the spreadsheet to a file automatically.  I need to right click on to export the spreadsheet.  I want to make the mathcad program automatic for other users.  If I use the component to writeprn, it creates a file with (0,0) cell information in it.  I appreciate any other ideas.

Thanks,
Ramesh

RE: how to write multiple vectors to a single file.

Ah, that is not a problem :)  Here's the beauty of the OLE-embedded Excel object.

Double click on the Excel object.  Notice that the menus at the top are suddenly those of Excel and not Mathcad.

Go to Tools>Macro>Visual Basic Editor.

In the project explorer view in the upper left, expand the VBAProject(Worksheet1) project.  Highlight "ThisWorkbook" and double click on it.

In the code window that comes up, paste this into it:

CODE

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    ThisWorkbook.SaveAs ("C:\Documents and Settings\Matt\Desktop\test1.xls")
End Sub

You can change what's in the quotes so that it points to the right filename.

Then close out of the visual basic editor and click back into Mathcad to take the focus away from the Excel object to save your changes.

So basically every time the Excel object is changed, the worksheet changes, and this function gets called to save your file.

It might require a tad more tweaking but that is the best I could figure out in 5 minutes.

Hope that helps!
Matt

RE: how to write multiple vectors to a single file.

(OP)
Matt,
Thanks for your spontaneous solution.  I implemented your suggestion and it works.  But the annoying thing is it asks a confirmation for every variable change in the spread sheet.  I have several variables passing to the spreadsheet so I need to click several times to accept the overwrite existing Excel file.  I wish there is a way to avoid this.

Ramesh

RE: how to write multiple vectors to a single file.

Hi Ramesh,

Yep, you're right, that overwrite confirmation dialog box does get a bit obnoxious after awhile.  If you are sure that you'd like to overwrite the file each time, you can use this code instead:

CODE

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Dim strFileName As String
    strFileName = "C:\Documents and Settings\Matt\Desktop\test1.xls"
    If Application.AlertBeforeOverwriting = True Then
        Application.AlertBeforeOverwriting = False
        ThisWorkbook.SaveAs (strFileName)
        Application.AlertBeforeOverwriting = True
    Else
        ThisWorkbook.SaveAs (strFileName)
    End If
End Sub

It just disables Excel's AlerBeforeOverwriting option if it is set.

Hope that helps!
Matt

RE: how to write multiple vectors to a single file.

(OP)
Matt,
the new program does not work.  It still asks to overwrite the existing file.  Would you please check the program?

Regards,
Ramesh

RE: how to write multiple vectors to a single file.

Hmmm, it works great for me.  What version of Excel are you using?

That code that I posted is to be copy/pasted in instead of the previous code you were using.  Just wanted to clarify that .  I'll take a look at it again.

Matt

RE: how to write multiple vectors to a single file.

(OP)
Matt,
I had Excel 97 and the program did not work.  I upgraded Excel to Excel 2000 but it is still not working.  Any help is appreciated.

thanks
Ramesh

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close