Drag and Drop - MatLab AppDesigner

Hi,
I'd like to a drag and drop a file to put it on the graphic interface of an App created with the Matlab AppDesigner but I didn't find out how. The drag and drop must be from a .mat file located on my computer to an Edit Field (Text) component, in order to be then reused through the program.
Any help would be appreciated :)
Thank you in advance for your answers

2 Comments

is drag and drop necessary? you can use uigetfile as an alternative
Hi,
Thank you for your return.
Yes, I'm aware of uigetfile, which works perfectly. However, drag and drop would be much more convenient and faster.
Regards

Sign in to comment.

 Accepted Answer

Prof. X
Prof. X on 12 Jan 2024
Edited: Prof. X on 15 Jan 2024
Have you seen this? It is a file drag and drop for uifigures.
I have used it with some success.

4 Comments

Hi,
Sorry for my late response and thank you for your return.
This is exactly what I was looking for. However, it works with a uifigure, and I'm trying to drag and drop files must be from a .mat file located on my computer to an Edit Field (Text) component of an App.
Do you know how I can proceed?
Thank you in advance,
Regards
It works for edit fields. I have included a sample .mat file for a test. Here is a quick script I wrote up and assuming you have the DnD_uifigure.m in your path, you will see you can drag files to the edit field and then load the data into field. Hope that helps and you have blessed day!
function TestDragandDrop
EditField = uieditfield(uifigure);
DnD_uifigure(EditField, @(EditField,File)CheckFile(EditField,File));
end
function CheckFile(EditField,File)
% Assuming your mat file has a .mat extension
[Path,FileName,Extension] = fileparts(File.names);
if strcmp(Extension,'.mat')
Data = load(File.names{:},'-mat');
EditField.Value = num2str(Data.Answer);
end
end
Hi Prof X,
I tried using this solution in both Matlab 2025a and 2024b, and it doesn't seem like the callback is getting called. I put in alerts/msgboxes in both the JavaScript inside the DnD_uifigure script, and in the CheckFile function. Is there something wrong in my code? I am using Rocky Linux 8.10 if that helps.
I was using MATLAB 2020b when I made this so there could be some version differences.
Did you try my example code specifically and it did not work?

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 9 Jan 2024

Commented:

on 11 Nov 2025

Community Treasure Hunt

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

Start Hunting!