Create a "Copy-Button" in MATLAB GUI

Hi,
i created a Matlab GUI and I need to add a button to copy the data that is presented in the uitable.
I need to create a matrix that contains als the three-dimensional ponits. So it needs to look like the uitable that in the attached fig-file, but the columns are seperated by comma.
I hope that somebody knows what I am looking for.
Thnaks in advance.

Answers (1)

(I modified your m-file to include pushbutton_Callback and pushbutton2_Callback in the handles structure so I could run those functions here in the Answers forum.)
h = bachelor;
handles = guidata(h);
handles.pushbutton_Callback(handles.figure1,[],handles) % same as clicking the "Calculate" button
I added a single line to pushbutton2_Callback, which is "get(handles.table1,'Data')", so that when the "Copy Data" button is pushed the contents of the uitable are displayed in the command window.
handles.pushbutton2_Callback(handles.figure1,[],handles) % same as clicking the "Copy Data" button
ans = 195×3
0 0 1.000000000000000 0.017150418627992 0 0.823370357174576 0.072731407686129 0 0.654969826345343 0.167425334872282 0 0.505049838368501 0.293716496272837 0 0.380416474388619 0.441054925718054 0 0.281320429539904 0.601052703191758 0 0.204120675587443 0.768451294767690 0 0.144506893175706 0.940201848235069 0 0.098822798983855 1.114545504736437 0 0.064258683622423
It sounds like that's the matrix you want to create.
Do you want to do something else with it?

3 Comments

Hi, Thanks for you help.
The problem is that in this order I can already copy it out of the fig-file. What I need is that the matrix looks like this:
0,0,100
4.30355742687535,0,72.8138938991728
18.0090453955277,0,48.9894489320377
So the columns need to be seperated bei comma. Because know i copy the data out of the uitable and excecute a command in excel to make it look that way. The copy-button is supposed to be a shortcut for this. And perfect would be if it automatically saves the marix in the clipboard, but I don't know exactly if this is possible.
Thnaks again.
And another problem would be that the matrix in the command window is shortened by the factor 100. So right know I need to multiply the matrix by 100 to get the points I want.
I tried it by adding the following lines to the m-file:
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
abc = get(handles.uitable1,'Data')
clipboard('copy',abc)
In this case the matrix is automatically saved in the clipboard, but it looks like this know
[0 0 100;1.71504186279923 0 82.3370357174576;7.27314076861285 0 65.4969826345343;.........]
And this is not what i need as well.
I don't know if my problem is even realizible.

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Asked:

on 14 Feb 2023

Commented:

on 15 Feb 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!