Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Excel to Matlab class

Subject: Excel to Matlab class

From: Philosophaie

Date: 5 Sep, 2008 01:16:03

Message: 1 of 7

Trying to take a cell from an Excel spreadsheet using
ActiveX controls and using that value in a MatLab equation
then placing the answer back into the spreadsheet.

This function:

function ExcelSinFn
exl = actxserver('excel.application');
exlWkbk = exl.Workbooks;
exlFile = exlWkbk.Open
(['C:\Folder\Sin from MatLab.xls']);
exlSheet1 = exlFile.Sheets.Item('Sheet1');
b=exlSheet1.Range('B3');
a=sin(b);
exlSheet1.Range('C3')=a;
exlWkbk.Close
exl.Quit
end

I get this error:

??? Function 'sin' is not defined for values of
class 'Interface.Microsoft_Excel_12.0_Object_Library.Range'.

Error in ==> sin at 14
  [varargout{1:nargout}] = builtin('sin', varargin{:});

Error in ==> ExcelSinFn at 8
a=sin(b);

Is there a class statement to change from Excel 12.0
Library to MatLab so that the sin function will work?

Subject: Excel to Matlab class

From: Bill August

Date: 5 Sep, 2008 07:38:55

Message: 2 of 7

> Trying to take a cell from an Excel spreadsheet using
>
> ActiveX controls and using that value in a MatLab
> equation
> then placing the answer back into the spreadsheet.
>
> This function:
>
> function ExcelSinFn
> exl = actxserver('excel.application');
> exlWkbk = exl.Workbooks;
> exlFile = exlWkbk.Open
> (['C:\Folder\Sin from MatLab.xls']);
> exlSheet1 = exlFile.Sheets.Item('Sheet1');
> b=exlSheet1.Range('B3');
> a=sin(b);
> exlSheet1.Range('C3')=a;
> exlWkbk.Close
> exl.Quit
> end
>
> I get this error:
>
> ??? Function 'sin' is not defined for values of
> class
> 'Interface.Microsoft_Excel_12.0_Object_Library.Range'.
>
> Error in ==> sin at 14
> [varargout{1:nargout}] = builtin('sin',
> ', varargin{:});
>
> Error in ==> ExcelSinFn at 8
> a=sin(b);
>
> Is there a class statement to change from Excel 12.0
> Library to MatLab so that the sin function will work?
Hi
b=exlSheet1.Range('B3');
b = b.Value ;
Regards.

Subject: Excel to Matlab class

From: Philosophaie

Date: 5 Sep, 2008 08:24:02

Message: 3 of 7

How do you take it back to Excel format in the next line?

Subject: Excel to Matlab class

From: Philosophaie

Date: 5 Sep, 2008 08:24:02

Message: 4 of 7

How do you take it back to Excel format in the next line?

Subject: Excel to Matlab class

From: Bill August

Date: 5 Sep, 2008 10:07:46

Message: 5 of 7

> How do you take it back to Excel format in the next
> line?
Hi,
Sorry i can not understand. Can you explain a little?
Do you mean to assign the value back to the excell cell?
Range.Value = b ;
Hope this can help.

Subject: Excel to Matlab class

From: Philosophaie

Date: 5 Sep, 2008 10:29:02

Message: 6 of 7

> > How do you take it back to Excel format in the next
> > line?
> Hi,
> Sorry i can not understand. Can you explain a little?
> Do you mean to assign the value back to the excell cell?
> Range.Value = b ;
> Hope this can help.

I need to change the class, a, from MatLab Class to Excel
11.0 class so the data can be sent to Excel.

b=exlSheet1.Range('B3');
b=b.Value;
a=sin(b);
"I need the code here to change 'a' to 'Microsoft Excel
11.0 class to send the resultant data back to Excel."
exlSheet1.Range('C3')=a;

Subject: Excel to Matlab class

From: Bill August

Date: 5 Sep, 2008 11:57:56

Message: 7 of 7

> > > How do you take it back to Excel format in the
> next
> > > line?
> > Hi,
> > Sorry i can not understand. Can you explain a
> little?
> > Do you mean to assign the value back to the excell
> cell?
> > Range.Value = b ;
> > Hope this can help.
>
> I need to change the class, a, from MatLab Class to
> Excel
> 11.0 class so the data can be sent to Excel.
>
> b=exlSheet1.Range('B3');
> b=b.Value;
> a=sin(b);
> "I need the code here to change 'a' to 'Microsoft
> Excel
> 11.0 class to send the resultant data back to Excel."
> exlSheet1.Range('C3')=a;
>
Hi
If you read my post carefully. You can find the solution is
range = exlSheet1.Range('C3') ;
range.Value = a ;

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us