Copy data from table created by MATLAB GUI

10 ビュー (過去 30 日間)
Masood Salik
Masood Salik 2021 年 10 月 8 日
回答済み: Ronit 2024 年 8 月 29 日
I have a table in GUI with some data. I wanted to copy selected data but Ctrl+C keys don't work here. Does there is anyoption to copy data from the table.

回答 (1 件)

Ronit
Ronit 2024 年 8 月 29 日
Hello Masood,
To copy data from a MATLAB GUI table, use the clipboard function in MATLAB. Using this function, you can copy and paste text to and from the system clipboard.
Create a “Copy” button in the GUI and write a callback function for it. This function should use clipboard function to transfer the table data to the system clipboard, allowing easy pasting elsewhere.
This is how you can create a “Copy” button and name the callback function:
uicontrol('Style', 'pushbutton', 'String', 'Copy to Clipboard', ...
'Position', [150, 10, 100, 30], ... % Adjust the position
'Callback', @(src, event)copyTableDataToClipboard(hTable));
Now define clipboard function using the callback function defined earlier:
data = hTable.Data;
% Convert the cell array to a string with tab-separated values
% Customize the data to retrieve that if required
clipboardStr = '';
for i = 1:size(data, 1)
rowStr = strjoin(cellfun(@num2str, data(i, :), 'UniformOutput', false), '\t');
clipboardStr = [clipboardStr, rowStr, '\n'];
end
% Copy the string to the clipboard
clipboard('copy', clipboardStr);
% Display a message to the user
msgbox('Table data copied to clipboard!');
Please refer to the following documentations for better understanding:
  1. clipboard: https://www.mathworks.com/help/matlab/ref/clipboard.html
  2. Creating Callbacks for Apps Created Programmatically: https://www.mathworks.com/help/matlab/creating_guis/write-callbacks-for-apps-created-programmatically.html

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by