What command could run any file.m chosen
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Samah EL QASSAH
am 29 Nov. 2016
Kommentiert: Jan
am 30 Nov. 2016
Hi!
I create a GUI that allow me to browse files.m with the code below:
function start_Callback(hObject, eventdata, handles)
indir2 = uigetfile;
set(handles.edit1, 'String', indir2);
I get this result:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/158485/image.png)
I want to run each time the selected file (regardless of the filename), but I still can not do it. How to proceed?
PS: I want to run the file via script.
0 Kommentare
Akzeptierte Antwort
Jan
am 29 Nov. 2016
What about considering the file path:
function start_Callback(hObject, eventdata, handles)
[FileName, FilePath] = uigetfile('*.m');
if ischar(FileName) % Not aborted
File = fullfile(FilePath, FileName);
set(handles.edit1, 'String', File);
run(File);
end
2 Kommentare
Weitere Antworten (1)
Fangjun Jiang
am 29 Nov. 2016
Bearbeitet: Fangjun Jiang
am 29 Nov. 2016
help run
FileName='c:\mydoc\test.m';
run(FileName);
6 Kommentare
Guillaume
am 29 Nov. 2016
Well, that would be because the code actually does not tell matlab to display the variables. Either remove the semicolons to tell matlab you want to display the result of the assignments, or use disp or fprintf.
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!