MATLAB Answers


how to write data to xls sheet?

Asked by Arun Badigannavar on 24 Jan 2013
      value_F = 0.1,0.2,0.3,0.4,0.5,0.6
      filename = 'C:\Documents and Settings\admin\Desktop\test.xlsx';
      Data= {'value_F';value_F};
      sheet = 1;
      xlRange = 'B';
where value_F is calculated from simulink model and asiigned to workspace,,,am able write oly value_F,,,am unable to write all the values of value_F



No tags are associated with this question.


No products are associated with this question.

4 Answers

Answer by Image Analyst
on 24 Jan 2013
 Accepted answer

Try using 'B1' for the range and not just 'B' - it should correspond to what ranges look like in Excel. Next, all cells in your cell array go into a cell in Excel, so you can't have a whole array in one cell. I've looked over my Excel writing code and I put all each element in a numerical array into their own cell. So have a for loop where you iterate over all numbers in your numerical array and put them into their own cell, something like this (untested):

[rows columns] = size(value_F);
myCellArray = cell(rows+1, columns);
myCellArray{1,1} = 'value_f'; % First row has only this
% Now assign rows 2 and lower of our cell array.
for col = 1 : columns
  for row = 1
    myCellArray{row+1, column} = myNumericalArray(row, column);
xlswrite(filename, myCellArray, sheet, xlRange)


Answer by Walter Roberson
on 24 Jan 2013

value_F = [0.1,0.2,0.3,0.4,0.5,0.6];

  1 Comment

for making simple,,i have shown some data for value_F here,,,but actually value_F is coming from workspace,,around hundred values i will get it,,how to write those

Answer by PG
on 24 Jan 2013

Check the type of workspace output variable using "whos ,var_name". It could be a problem with type of data being written in excel.

  1 Comment

 value_F       2x1                16  double        

Answer by Jing
on 24 Jan 2013
Edited by Jing
on 24 Jan 2013

If there're both CHAR data and DOUBLE data, I prefer to use XLSWRITE twice to make it work without extra effort. Here I assume value_F is a double matrix.



No am unable to write both string and double value to xls sheet

on 24 Jan 2013

Just use the code I provided above, it can do that, just write twice...

thanks am able to write it,,,

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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!