필터 지우기
필터 지우기

How can I open multiple bin files from one folder with uigetfile command?

조회 수: 1 (최근 30일)
Kofial
Kofial 2019년 12월 5일
댓글: Kofial 2019년 12월 11일
Here is the code for one file.
[filename, pathname] = uigetfile('*.bin', 'Drohnenmessdatei auswahlen');
if isequal(filename, 0)
disp('User selected ''Cancel''')
else
disp(['Datei ausgewahlt: ', fullfile(pathname, filename)])
end
datei=dir(fullfile(pathname, filename));
dateigroesse_bytes=datei.bytes;
dateigroesse_bytes= round(dateigroesse_bytes/72);
fileID = fopen(filename);
bool_var_a_da = exist ('a', 'var')
if(bool_var_a_da == 0)
a =1;
Zeitstempel=zeros(dateigroesse_bytes,6);
else
end
I tried with
[filename, pathname] = uigetfile('*.bin', 'Select file','MultiSelect','on');
but it doesnt work.

답변 (2개)

Walter Roberson
Walter Roberson 2019년 12월 5일
When you use multiselect in uigetfile, then you need to use something like
if isnumeric(filename)
disp('User selected ''Cancel''');
return
end
if ~iscell(filename)
filename = {filename};
end
This is because if the user only selected one file, then what is returned is the character vector of the file name, but if the user selected more than one, then what is returned is a cell array of character vectors.
Instead of the second if that I show there, you can just code
filename = cellstr(filename);
cellstr() leaves the input as-is if it is already a cell array, but converts the input to cell array of character vectors if the input is character.
  댓글 수: 2
Kofial
Kofial 2019년 12월 5일
It doesn't work. Gives this error:
Error in matlab.ui.internal.dialog.FileChooser/updateFromDialog (line 215)
obj.PathName = filepaths{1};
Error in matlab.ui.internal.dialog.FileChooser/prepareDialog/localupdate (line 95)
updateFromDialog(obj,updateDataObject(obj));
Walter Roberson
Walter Roberson 2019년 12월 5일
Is there more to the error message? What triggers that message? At the moment it looks like a problem in the internal code. Which operating system are you using, and which MATLAB version are you using?

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


Kofial
Kofial 2019년 12월 9일
Hi. You were right, was a problem of the system. Sorry Im still new in matlab and Im still trying to learn .
When I use your suggestion it gives this:
Error using dir
Name must be a string scalar or character vector.
Error in Binaerdaten_Drohne_V2 (line 24)
datei=dir(fullfile(pathname, filename));
I guess I will need a command to combine different cell arrays into one.
I tried with filename = strjoin(filename) but it doesn't work.
Files look like this:
00191009.bin 00191010.bin.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 12월 9일
if isnumeric(filename)
disp('User selected ''Cancel''');
return
end
filename = cellstr(filename);
fullnames = fullfile(pathname, filename);
numfiles = length(fullnames);
output = cell(1, numfiles);
dateigroesse_bytes = zeros(1, numfiles);
for K = 1 : numfiles
thisfile = filenames{K};
datei = dir(thisfile);
dateigroesse_bytes(K) = datei.bytes;
dateigroesse_bytes(K) = round(dateigroesse_bytes(K)/72);
fileID = fopen(thisfile);
bool_var_a_da = exist ('a', 'var');
if (bool_var_a_da == 0)
a =1;
Zeitstempel = zeros(dateigroesse_bytes(K),6);
end
now do something to calculate a result and store it in outputs{K}
end

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

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by