How to use the same directory for all functions in app designer?

조회 수: 3 (최근 30일)
Lavanya
Lavanya 2022년 6월 24일
편집: Lavanya 2022년 7월 5일
I have created a GUI, in that when I add the data from a folder it will load .csv and text files. Now I wanted to add images(.png) lauanch with image viewer from the same directory in app designer.
(Here I have enclosed the example file. i.e It will ask for the select file from the directory after that it launches windows media player with the file.)
But for GUI, without using the 'baseFileName = uigetfile('*.png')' , Is it possible to select from the directory? by using 'uigetfile' it is again asking to select the folder.
for example : it should be like this baseFileName = '*.png'
  댓글 수: 1
Jan
Jan 2022년 6월 24일
I do not understand, what you are asking for. Do you want to process all PNGs fils inside a specific folder?
Folder = 'D:\Yor\Folder';
FileList = dir(fullfile(Folder, '*.png'));
for k = 1:numel(FileList)
aFile = fullfile(FileList(k).folder, FileList(k).name);
% Now do what you need with this file
end

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

채택된 답변

Image Analyst
Image Analyst 2022년 6월 24일
This works on my computer:
Folder = 'E:\Movies';
% FileList = dir(fullfile(Folder, '*.mkv'));
FileList = dir(fullfile(Folder, '*.wmv'))
% Not sure WMP plays .mkv files???? Does it?
if isempty(FileList)
errorMessage = sprintf('Error: no video files found in\n%s.', Folder);
fprintf('%s\n', errorMessage)
uiwait(warndlg(errorMessage));
return;
else
fprintf('Found %d videos in "%s".\n', length(FileList), Folder);
end
% Play all videos one after the other.
for k = 1:numel(FileList)
fullFileName = fullfile(FileList(k).folder, FileList(k).name);
% First construct the command line for the system() function.
% Enclose all filenames in double quotes because we may have spaces in the filenames.
arguments = sprintf('"%s"', fullFileName);
commandLine = sprintf('"%s" %s', editorFullFileName, arguments);
fprintf('%s', commandLine);
system(commandLine);
promptMessage = sprintf('Do you want to play the next video,\nor Quit processing?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
return; % or break or continue.
end
end
  댓글 수: 10
Lavanya
Lavanya 2022년 6월 28일
Ok, thank you . I will try these
Lavanya
Lavanya 2022년 7월 4일
편집: Lavanya 2022년 7월 5일
I have create two apps. 1.GUI
2. Listboxedit
From GUI button click, it will open a new window with the Listbox data( it will open 2nd app ListBox edit). Till now Its working good.
But I wanted to activate the app2. When I click moveup it should change the Listorder by moving upward button. In Editfield, it should show Listbox name. Finally I wanted to save all these details and it should update data in Main GUI.
I have enclosed the image and code should work like this
For your reference I have enclosed the ListBox edit. kindly suggest a way for this?

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

추가 답변 (2개)

Image Analyst
Image Analyst 2022년 6월 24일
Try this:
folder = pwd; % wherever you want
% Get a list of all .txt, .png, and .csv files:
fileList = [...
dir(fullfile(folder, '*.txt'));...
dir(fullfile(folder, '*.png'));...
dir(fullfile(folder, '*.csv'))]
% If you want all the names put one cell array:
allFileNames = fullfile({fileList.folder}, {fileList.name})'
% Now files are listed in the order you called dir().
% If you want the list sorted alphabetically:
allFileNames = sort(allFileNames)

Kevin Holly
Kevin Holly 2022년 6월 24일
You could have the app load the directory files into a dropdown box after selecting a particular file as shown in the example attached.
  댓글 수: 2
Lavanya
Lavanya 2022년 6월 24일
I am unable to open this file. Can you please help me with this?
Kevin Holly
Kevin Holly 2022년 6월 24일
What version of MATLAB do you have? I created the above in R2022a.

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by