필터 지우기
필터 지우기

What command could run any file.m chosen

조회 수: 1 (최근 30일)
Samah EL QASSAH
Samah EL QASSAH 2016년 11월 29일
댓글: Jan 2016년 11월 30일
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:
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.

채택된 답변

Jan
Jan 2016년 11월 29일
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
Samah EL QASSAH
Samah EL QASSAH 2016년 11월 29일
편집: Samah EL QASSAH 2016년 11월 29일
Thanks, it works except for one m-file. This m-file contains just a variable set that must be displayed on workspace after its execution.
the file contains these variabls:
Pass = 0;
Coss = 1;
Tass = 0;
....
But after execution, nothing is displayed on the workspace.
Jan
Jan 2016년 11월 30일
Why do you assume that anything is displayed where?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2016년 11월 29일
편집: Fangjun Jiang 2016년 11월 29일
help run
FileName='c:\mydoc\test.m';
run(FileName);
  댓글 수: 6
Guillaume
Guillaume 2016년 11월 29일
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.
Samah EL QASSAH
Samah EL QASSAH 2016년 11월 30일
I find the solution:
function Browse_Calib_Callback(hObject, eventdata, handles)
indir2 = uigetfile;
set(handles.edit2, 'String', indir2)
run(indir2);
indir2 = indir2(1:end-2);
evalin('base', indir2);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by