Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

LiveLink with Excel - extract data from an exiting Table

Please login with a confirmed email address before reporting spam

Hello,

I am trying to extract data from the results and show it in excel. I followed the following procedure:

  1. In COMSOL I was able to define a table and save its content on an excel file
  2. Saved the mph as VBA
  3. open excel and pates the VBA code into a new module
  4. run the script

Up to now everything was OK.

So I have a table (tbl1) with two columns (frequency and gain) Now I need to perform what in Matlab code would be

Gain = mphtable(model,'tbl1'); Freq=Gain.data(:,1); Gain_dB=Gain.data(:,2);

I could not find the VBA equivalent of these 3 MATLAB lines (and yes, I did looked into the LiveLink for Excel, but in the EXTRACTING DATA section I was not able to find what I was looking for, or misinterpreted)

Any ideas?

Thanks

-------------------
Tuli

1 Reply Last Post Apr 10, 2019, 7:05 a.m. EDT
Kristoffer Raneflod COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 5 years ago Apr 10, 2019, 7:05 a.m. EDT

Hello,

Perhaps the following code can be used in your case:

Dim tableData() As String
tableData = model.result.get_table("tbl1").getTableData(True)

Dim Freq, Gain As Variant
Freq = Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Index(tableData, 0, 1)) 'Retrieve the values from the first column, and transpose.
Gain = Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Index(tableData, 0, 2)) 'Retrieve the values from the second column, and transpose.

The code use the Index worksheet function for retrieving the values from the columns, and the Transpose worksheet function for transposing the data.

Best regards, Kristoffer

Hello, Perhaps the following code can be used in your case: Dim tableData() As String tableData = model.result.get_table("tbl1").getTableData(True) Dim Freq, Gain As Variant Freq = Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Index(tableData, 0, 1)) 'Retrieve the values from the first column, and transpose. Gain = Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Index(tableData, 0, 2)) 'Retrieve the values from the second column, and transpose. The code use the Index worksheet function for retrieving the values from the columns, and the Transpose worksheet function for transposing the data. Best regards, Kristoffer

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.