tota_mcsd
tota_mcsd

Reputation: 3

Entering data into excel sheet using matlab

I am entering a dynamic data into excel sheet from a textbox. The problem is that it enters letter by letter in every cell.

This is the code I have tried:

 >>function bntEnterData_callback(hObject,eventdata,handles)
 >>val1 = get(handles.txt1,'string'));
 >>val2 = get(handles.txt2,'string'));
 >>val3 = get(handles.txt3,'string'));
 >>values = [ val1 val2 val3]
 >>filename= 'try.xls';
 >>sheet= 1;
 >>xkRange= 'A2';
 >>xlswrite(filename,values,sheet,xlRange);

Upvotes: 0

Views: 47

Answers (1)

sco1
sco1

Reputation: 12214

Assuming your handles.txt* are edit uicontrols, the 'String' property is going to be a character vector. Concatenating multiple character vectors just creates a longer vector:

a = 'foo';
b = 'bar';
values = [a b]

Which creates:

values =

    'foobar'

When not explicitly provided a range of cells to write to, xlswrite will interpret the input single cell (or the default A1) as the starting point, and write all elements of the input array using the single cell as the origin. Because 'foobar' is an array of characters, this gives the expected behavior of:

no

To fix this, concatenate into a cell array:

a = 'foo';
b = 'bar';
values = {a b};

filename= 'try.xls';
sheet= 1;
xlRange= 'A2';
xlswrite(filename,values,sheet,xlRange);

yay

Upvotes: 1

Related Questions