cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Matlab data to Mathcad

OpticGuy
1-Newbie

Matlab data to Mathcad

Hi guys. I have an important question. I have a my full program of OFDM and a laser to modulate it in Matlab. its optical communication.

Now I have a solid complicated nonlinear Schrodinger equation that defines my optical fibre. To program it in matlab, it might take ages. Cause it concerns partial derivative and so on.

so I thought may be I can write that equation in Mathcad, and get the data across the laser to Mathcad. Do the math and get the values back to Matlab.

Is that possible?

thank you. If you have any suggestion on this or perhaps any tutorial, please share it with me. Thank you very much!

1 ACCEPTED SOLUTION

Accepted Solutions

Hello!

You can find a link to the guide "Developer's Reference" in "Mathcad Help" (F1 key):

Mathcad_Help.jpg

Or use the direct link: C:\Program Files\Mathcad\Mathcad 15\doc\HELP_EN\DevRef\DevRef.htm

Developer

P.S. Also look in the Help topic "MATLAB Component". Quote: "In addition to importing and exporting MATLAB data files using the File Input, File Output, or Data Table components, you can also use the MATLAB component to execute MATLAB scripts using data from your Mathcad worksheet, and return the results to Mathcad."

MATLAB_Component.jpg

View solution in original post

27 REPLIES 27
RichardJ
19-Tanzanite
(To:OpticGuy)

so I thought may be I can write that equation in Mathcad, and get the data across the laser to Mathcad. Do the math and get the values back to Matlab.

Is that possible?

Yes. You need to call Mathcad from Matlab using the automation interface. See the Developers Reference under the help menu.

Hi Richard. Thanks for your reply. Where can I find this developers reference? Please advice. Thank you.

RichardJ
19-Tanzanite
(To:OpticGuy)

Look under the help menu in Mathcad.

Hello!

You can find a link to the guide "Developer's Reference" in "Mathcad Help" (F1 key):

Mathcad_Help.jpg

Or use the direct link: C:\Program Files\Mathcad\Mathcad 15\doc\HELP_EN\DevRef\DevRef.htm

Developer

P.S. Also look in the Help topic "MATLAB Component". Quote: "In addition to importing and exporting MATLAB data files using the File Input, File Output, or Data Table components, you can also use the MATLAB component to execute MATLAB scripts using data from your Mathcad worksheet, and return the results to Mathcad."

MATLAB_Component.jpg

It depends which version of Matlab you are using. The Mathcad component won't accept the more recent versions of Matlab. I can't remember what versions it will work with, but certainly no version after (and including) 2008b. It might be easier to dump the data to a text or csv file, say, and transfer that.

Alan

Hi Alan. I have the most recent Matlab version. Do you know where I can find regarding this interface properties according to versions. Is it easy to do it over excel? Is it easy to import?

MikeArmstrong
5-Regular Member
(To:OpticGuy)

Is it easy to do it over excel? Is it easy to import?

Mathcad has built in functions which allow data to be written to Excel. There are also many scripted components which will allow this.

Mike

For data out of Mathcad look up WRITEPRN in the help file or investigate the Excel component.

For data into Matlab try 'help load' or 'help xlsread' within Matlab.

Alan

Guys. Thanks all for the quick response. Im using Mathcad 14. So I can save the data from Matlab to excel. Then import it to Mathcad. Do the calculations. Export it to excel and load or xlsread back to matlab.

Is the procedure right? Thanks again guys!!

MikeArmstrong
5-Regular Member
(To:OpticGuy)

So I can save the data from Matlab to excel. Then import it to Mathcad. Do the calculations. Export it to excel and load or xlsread back to matlab.

Is the procedure right? Thanks again guys!!

Yes that seems to work.

Mike

RichardJ
19-Tanzanite
(To:OpticGuy)

I was under the impression from your first post that Matlab is controlling the laser modulation, and as part of that control you want to pass data to Mathcad, do some calculations and get the answer back. So you would need something that is fully automated (no manual saving and loading of files, etc), and Matlab, not Mathcad, has to be in control. Is that correct?

hi Richard. After the laser modulation part. I can stop the process, grab the data, and run it in mathcad. And bring it back to Matlab. I thought It should be automated. But since its getting very complicated. I have to do the manual process.

Do you think I have an alternative? Thank you.

RichardJ
19-Tanzanite
(To:OpticGuy)

hi Richard. After the laser modulation part. I can stop the process, grab the data, and run it in mathcad. And bring it back to Matlab.

OK. I see.

Do you think I have an alternative? Thank you.

Like I said, you can call Mathcad via the automation interface (i.e. as a COM object). Whether it's worth the effort of writing the code to do that depends on your level of experience calling things such as ActiveX controls (also COM objects) from within Matlab, and how many times you you are going to have to port data back and forth. There are not many steps required to push the data over and get the answer back.

Launch Mathcad (or link to it if it's already running)

Load the worksheet (if not already loaded)

Use the Worksheet.SetValue method to send the data over.

Use the Worksheet.Recalculate method to force recalculation

Use the Worksheet.GetValue method to get the answer back

Optionally, close the worksheet and/or Mathcad.

Hi Richard. Sorry for asking this again. So the idea now is,

writing a code in Matlab. Which means it will call a function sort of Mathcad in this case. Which needs ActiveX or COM objects. What do meant by worksheet, I dont understand that part.

Now say I have ran until the laser. I wana bring the data to Mathcad, so I open Mathcad. In the same Matlab program, I define a function that delivers the particular data to Mathcad. Then go Mathcad, run it by myself. Then go back to matlab, and make it call the values back. Is excel involved in between any of this procedure?

Many thanks!

RichardJ
19-Tanzanite
(To:OpticGuy)

writing a code in Matlab. Which means it will call a function sort of Mathcad in this case. Which needs ActiveX or COM objects.

Matlab can call another piece of software if that software is COM compliant. Mathcad is COM compliant.

What do meant by worksheet, I dont understand that part.

The Mathcad "program" or "document"

Now say I have ran until the laser. I wana bring the data to Mathcad, so I open Mathcad. In the same Matlab program, I define a function that delivers the particular data to Mathcad. Then go Mathcad, run it by myself. Then go back to matlab, and make it call the values back. Is excel involved in between any of this procedure?

Not quite. Your Matlab program launches Mathcad, loads the correct worksheet, sends the data over, forces Mathcad to recalculate the worksheet, grabs the answer back, closes Mathcad. You do not have to do anything at all (other than write the Matlab code that does this, of course ). There is no need for Excel or any other piece of software.

Hi Richard.... your wink looks a bit scary... i hope its not. Cause I got the idea of your explanation. But I got no idea how the code going to be. By chance, do you have any example? Cause I googled it, I cant really find proper information with sort of examples, other then Mathcad help notes in google.

Sorry if its too much too ask, if you dont mind sharing any if you have... But seriously thanks a lot!!

RichardJ
19-Tanzanite
(To:OpticGuy)

If I had an example I would have already posted it. I don't use Matlab though, so I don't have an example. I am 100% certain it can be done though. I can give you an example written in VBA, in which Excel calls Mathcad, but not a Matlab example. I think I know someone that might be able to provide such an example though. In fact, I'm kind of surprised he hasn't already commented in this thread. I'll send him an e-mail and ask him about it.

Thanks Richard!! Im glad that I found this forum!!! Thanks a lot!!

PhilipOakley
5-Regular Member
(To:OpticGuy)

Richard prompted me: This is from an internal newsletter I wrote a while back

I tried to paste it (the content via cut & paste) in but it won't let me! so see the attachments.

http://collab.mathsoft.com/~Mathcad2000 has all the details - search for 'philip matlab' between 1 oct 2006 and 1 oct 2007 for some other threads

Thanks Philip

big_grin.gif

Thank you very much Philip. I will carry out from here. Thanks a lot everyone.

Richard, appreciate your help a lot!!

RichardJ
19-Tanzanite
(To:OpticGuy)

Don't worry about it. You are not using the Matlab component, which allows caling Matlab from Mathcad. You are going the other way: Matlab is calling Mathcad.

True! However, because this would be a lot more complicated than simply inserting a pre-existing component, I suspect it would be far quicker to program the pde directly within Matlab (it's not that difficult to do - though it isn't as straightforward as in Mathcad). My vote is still for data transfer using the Excel component!

Alan

Hi guys. I look up on how to import data from Mathcad to Matlab... if any shortcuts... cheers guys!

MikeArmstrong
5-Regular Member
(To:OpticGuy)

Hi guys. I look up on how to import data from Mathcad to Matlab... if any shortcuts... cheers guys!

Unless your Mathcad version is compatible with the version of Matlab, I very much doubt you'll find a quicker way. Just set the Mathcad worksheet up so it can be used multiple time.

Mike

Hi VladimirN. Thanks for such detailed answer. Appreciate it a lot. I will try it on.

Which version of Mathcad you use?

Top Tags