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:
How to copy and past Excel-data into a MATLAB GUI table?

Subject: How to copy and past Excel-data into a MATLAB GUI table?

From: Sebastian Gatzka

Date: 19 Nov, 2012 08:49:13

Message: 1 of 6

Hello world,

i really would like to paste rows and columns from Excel into a MATLAB GUI table.
So far, if I past into the table all the data is crammed into the one cell which is currently highlighted.
Thats not what I want, but to preserve the rows and columns from Excel.

Any ideas how this can be managed?

Thanks in advance!
Sebastian

Subject: How to copy and past Excel-data into a MATLAB GUI table?

From: Ryan

Date: 25 Nov, 2012 14:43:09

Message: 2 of 6

I just stumbled across this post. I wonder why no one has offered a suggestion yet. Well, nevertheless, here's my recommendation. please read this:
http://www.mathworks.com/help/matlab/ref/xlsread.html

That is probably the single best comprehensive resource for integrating Matlab and Excel. Here is a single line of code that will import excel data into Matlab:
[num,txt,raw] = xlsread('C:\Program Files\MATLAB\R2012a\Symbols.xls')

Just change the path to your own Excel file.

"Sebastian Gatzka" <sebastian.gatzka.NOSPAM@gmx.de> wrote in message <k8crq9$g3f$1@newscl01ah.mathworks.com>...
> Hello world,
>
> i really would like to paste rows and columns from Excel into a MATLAB GUI table.
> So far, if I past into the table all the data is crammed into the one cell which is currently highlighted.
> Thats not what I want, but to preserve the rows and columns from Excel.
>
> Any ideas how this can be managed?
>
> Thanks in advance!
> Sebastian

Subject: How to copy and past Excel-data into a MATLAB GUI table?

From: Sebastian Gatzka

Date: 26 Nov, 2012 00:27:09

Message: 3 of 6

Thank you Ryan,

but I don't want to work with files, I need a copy & past function.

"Ryan" wrote in message <k8tapt$m4t$1@newscl01ah.mathworks.com>...
> I just stumbled across this post. I wonder why no one has offered a suggestion yet. Well, nevertheless, here's my recommendation. please read this:
> http://www.mathworks.com/help/matlab/ref/xlsread.html
>
> That is probably the single best comprehensive resource for integrating Matlab and Excel. Here is a single line of code that will import excel data into Matlab:
> [num,txt,raw] = xlsread('C:\Program Files\MATLAB\R2012a\Symbols.xls')
>
> Just change the path to your own Excel file.
>
> "Sebastian Gatzka" <sebastian.gatzka.NOSPAM@gmx.de> wrote in message <k8crq9$g3f$1@newscl01ah.mathworks.com>...
> > Hello world,
> >
> > i really would like to paste rows and columns from Excel into a MATLAB GUI table.
> > So far, if I past into the table all the data is crammed into the one cell which is currently highlighted.
> > Thats not what I want, but to preserve the rows and columns from Excel.
> >
> > Any ideas how this can be managed?
> >
> > Thanks in advance!
> > Sebastian

Subject: How to copy and past Excel-data into a MATLAB GUI table?

From: Sumit Tripathi

Date: 8 Jan, 2013 02:09:09

Message: 4 of 6

Following code would work for you. I tested it with GUIDE. I just created a pushbutton with following callback fuction. The callback would paste the data into the table with tag 'uitable1'.

import = importdata('-pastespecial');
%% Convert Nx1 cell array into NxM cell array. The delimiter in each row is TAB character %ASCII value 9
import1={};
for i=1:length(import(:,1))
    TAB_char=regexpi(import{i},char(9));%find tabs
    temp={import{i}(1:TAB_char(1))};
    for comma_i=2:length(TAB_char)
        temp=[temp,{import{i}(TAB_char(comma_i-1):TAB_char(comma_i))}];
    end
    temp=[temp,{import{i}(TAB_char(end):end)}];
    import1=[import1;temp];
end
set(handles.uitable1,'Data',import1);


"Sebastian Gatzka" <sebastian.gatzka.NOSPAM@gmx.de> wrote in message <k8crq9$g3f$1@newscl01ah.mathworks.com>...
> Hello world,
>
> i really would like to paste rows and columns from Excel into a MATLAB GUI table.
> So far, if I past into the table all the data is crammed into the one cell which is currently highlighted.
> Thats not what I want, but to preserve the rows and columns from Excel.
>
> Any ideas how this can be managed?
>
> Thanks in advance!
> Sebastian

Subject: How to copy and past Excel-data into a MATLAB GUI table?

From: Flavio Prattico

Date: 26 Feb, 2014 10:15:16

Message: 5 of 6

"Sebastian Gatzka" <sebastian.gatzka.NOSPAM@gmx.de> wrote in message <k8crq9$g3f$1@newscl01ah.mathworks.com>...
> Hello world,
>
> i really would like to paste rows and columns from Excel into a MATLAB GUI table.
> So far, if I past into the table all the data is crammed into the one cell which is currently highlighted.
> Thats not what I want, but to preserve the rows and columns from Excel.
>
> Any ideas how this can be managed?
>
> Thanks in advance!
> Sebastian

Hi Sebastian,
I answer to your post many time later but now I'm working with a similar problem and still today there are no solution on internet.

My solution is the follow:

    function copyExcel_callback(hO, ev, handles)
        str = clipboard('paste');
        str = strrep(str,',','.');
        import=str2num(str);
        set(t1, 'Data', import);
    end

this is the function of a push button that paste into the table named t1 what is copied in the clipboard. This code include also the solution of the problem that in excel the decimal is marked with the comma.

Bye Flavio

Subject: How to copy and past Excel-data into a MATLAB GUI table?

From: Kyle

Date: 1 Apr, 2014 13:22:08

Message: 6 of 6

"Flavio Prattico" <flavioprattico@gmail.com> wrote in message <lekerk$ai9$1@newscl01ah.mathworks.com>...
> "Sebastian Gatzka" <sebastian.gatzka.NOSPAM@gmx.de> wrote in message <k8crq9$g3f$1@newscl01ah.mathworks.com>...
> > Hello world,
> >
> > i really would like to paste rows and columns from Excel into a MATLAB GUI table.
> > So far, if I past into the table all the data is crammed into the one cell which is currently highlighted.
> > Thats not what I want, but to preserve the rows and columns from Excel.
> >
> > Any ideas how this can be managed?
> >
> > Thanks in advance!
> > Sebastian
>
> Hi Sebastian,
> I answer to your post many time later but now I'm working with a similar problem and still today there are no solution on internet.
>
> My solution is the follow:
>
> function copyExcel_callback(hO, ev, handles)
> str = clipboard('paste');
> str = strrep(str,',','.');
> import=str2num(str);
> set(t1, 'Data', import);
> end
>
> this is the function of a push button that paste into the table named t1 what is copied in the clipboard. This code include also the solution of the problem that in excel the decimal is marked with the comma.
>
> Bye Flavio

Hi Flavio,

I was having similar problems that made it difficult to use uitable without have to do a ton of different cases for each type of data that I wanted to copy and paste. This File Exchange submission seems to solve a lot of those problems and is easy to use:

http://www.mathworks.com/matlabcentral/fileexchange/28016-straightforward-copy-and-paste-functions

Good Luck,
Kyle

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