Thread Subject: add dynamically new data from gui to an excel file

Subject: add dynamically new data from gui to an excel file

From: Teodor

Date: 23 Oct, 2009 11:55:10

Message: 1 of 6

Hello!

I have a problem in adding new data from matlab into an xls file.
In my gui project I have a edit box for Time...where I write the time value for creating later a vector.... I want to save into an excel file, in a certain column called Time, every time I enter a new value.
How can I do this? because only with:
d=value of time written in the box
xlswrite('Test.xls',d,'Test','E3');
I can write only in the column E at the 3-rd row., and if I write another value, then the previous value will be overwritten.
Can you help me with this problem?
Thanks in advance!

Subject: add dynamically new data from gui to an excel file

From: ImageAnalyst

Date: 23 Oct, 2009 12:14:25

Message: 2 of 6

On Oct 23, 7:55 am, "Teodor " <teodoralexan...@yahoo.com> wrote:
> Hello!
>
> I have a problem in adding new data from matlab into an xls file.
> In my gui project I have a edit box for Time...where I write the time value for creating later a vector.... I want to save into an excel file, in a certain column called Time, every time I enter a new value.
> How can I do this? because only with:
> d=value of time written in the box
> xlswrite('Test.xls',d,'Test','E3');
> I can write only in the column E at the 3-rd row., and if I write another value, then the previous value will be overwritten.
> Can you help me with this problem?
> Thanks in advance!

----------------------------------------------------------------------------------------------
Just increment the row after each poke, something like this (untested)

excelRow = 3; % Row for the first write.
for k = 1 : 1000
  d = GetTime(); % Whatever function you call...
  cellReference = sprintf('E%d', excelRow);
  xlswrite('Test.xls', d, 'Test', cellReference);
  excelRow = excelRow + 1;
end

P.S. This will be very, very slow. I suggest you use xlswrite1
instead (get it from the FileExchange).

Subject: add dynamically new data from gui to an excel file

From: Teodor

Date: 23 Oct, 2009 13:20:20

Message: 3 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <38baf333-9396-4fa1-944f-e3033ebe1fc9@k26g2000vbp.googlegroups.com>...
> On Oct 23, 7:55?am, "Teodor " <teodoralexan...@yahoo.com> wrote:
> > Hello!
> >
> > I have a problem in adding new data from matlab into an xls file.
> > In my gui project I have a edit box for Time...where I write the time value for creating later a vector.... I want to save into an excel file, in a certain column called Time, every time I enter a new value.
> > How can I do this? because only with:
> > d=value of time written in the box
> > xlswrite('Test.xls',d,'Test','E3');
> > I can write only in the column E at the 3-rd row., and if I write another value, then the previous value will be overwritten.
> > Can you help me with this problem?
> > Thanks in advance!
>
> ----------------------------------------------------------------------------------------------
> Just increment the row after each poke, something like this (untested)
>
> excelRow = 3; % Row for the first write.
> for k = 1 : 1000
> d = GetTime(); % Whatever function you call...
> cellReference = sprintf('E%d', excelRow);
> xlswrite('Test.xls', d, 'Test', cellReference);
> excelRow = excelRow + 1;
> end
>
> P.S. This will be very, very slow. I suggest you use xlswrite1
> instead (get it from the FileExchange).

I've tried your solution but it doesn't work as I want... In the excel file there will be written the time value(only one and when you change it, the previous will be overwritten) for 1000 times in the E column starting from the 3-rd row...

Subject: add dynamically new data from gui to an excel file

From: someone

Date: 23 Oct, 2009 14:07:19

Message: 4 of 6

"Teodor " <teodoralexandra@yahoo.com> wrote in message <hbsaik$2d5$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <38baf333-9396-4fa1-944f-e3033ebe1fc9@k26g2000vbp.googlegroups.com>...
> > On Oct 23, 7:55?am, "Teodor " <teodoralexan...@yahoo.com> wrote:
> > > Hello!
> > >
> > > I have a problem in adding new data from matlab into an xls file.
> > > In my gui project I have a edit box for Time...where I write the time value for creating later a vector.... I want to save into an excel file, in a certain column called Time, every time I enter a new value.
> > > How can I do this? because only with:
> > > d=value of time written in the box
> > > xlswrite('Test.xls',d,'Test','E3');
> > > I can write only in the column E at the 3-rd row., and if I write another value, then the previous value will be overwritten.
> > > Can you help me with this problem?
> > > Thanks in advance!
> >
> > ----------------------------------------------------------------------------------------------
> > Just increment the row after each poke, something like this (untested)
> >
> > excelRow = 3; % Row for the first write.
> > for k = 1 : 1000
> > d = GetTime(); % Whatever function you call...
> > cellReference = sprintf('E%d', excelRow);
> > xlswrite('Test.xls', d, 'Test', cellReference);
> > excelRow = excelRow + 1;
> > end
> >
> > P.S. This will be very, very slow. I suggest you use xlswrite1
> > instead (get it from the FileExchange).
>
> I've tried your solution but it doesn't work as I want... In the excel file there will be written the time value(only one and when you change it, the previous will be overwritten) for 1000 times in the E column starting from the 3-rd row...

% Are you sure? It seems to work for me.
% If I run the following from the MATLAB command window:

excelRow = 3; % Row for the first write.
for k = 1 : 1000
 d = k; % Whatever function you call...
 cellReference = sprintf('E%d', excelRow);
 xlswrite('Test.xls', d, 'Test', cellReference);
 excelRow = excelRow + 1;
end

MATLAB creates a Test.xls file with a Test worksheet
that has numbers from 1 to 10 in rows E3 to E12.

Maybe you need to clear or delete the Test.xls file
first before running the above code.

Subject: add dynamically new data from gui to an excel file

From: someone

Date: 23 Oct, 2009 14:16:19

Message: 5 of 6

>
> % Are you sure? It seems to work for me.
> % If I run the following from the MATLAB command window:
>
> excelRow = 3; % Row for the first write.
> for k = 1 : 1000
> d = k; % Whatever function you call...
> cellReference = sprintf('E%d', excelRow);
> xlswrite('Test.xls', d, 'Test', cellReference);
> excelRow = excelRow + 1;
> end
>
> MATLAB creates a Test.xls file with a Test worksheet
> that has numbers from 1 to 10 in rows E3 to E12.
>
> Maybe you need to clear or delete the Test.xls file
> first before running the above code.

% OOPS... Sorry in the above, I changed
for k = 1 : 1000
% to
for k = 1 : 10
% for testing.

Subject: add dynamically new data from gui to an excel file

From: ImageAnalyst

Date: 23 Oct, 2009 17:56:07

Message: 6 of 6

Like someone, I also tried it (with 3 iterations). It does work. The
different time values are written out row by row. Each number goes
into it's own new row right beneath the old one. You said that you
were overwriting cell E3 every time and apparently didn't like that.
You were writing into cell E3 because you apparently didn't know how
to change the cell reference at each iteration and had just hard-coded
'E3' into the argument list. I gave you code to put the values into a
different cell each time.

But look at what I said about it taking a long time. Take this VERY
seriously:
If you have 1000 iterations you do not (repeat DO NOT) want to call
xlswrite.
It will take forever (> hours) and you'll think it hung.
Either use xlswrite1 or simply write out the data to a csv file using
fprintf(). It will be so much faster.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
matlab to excel Alexandra Teodor 23 Oct, 2009 07:59:19
rssFeed for this Thread

Contact us at files@mathworks.com