How can I open multiple bin files from one folder with uigetfile command?
2 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (2 件)
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 件のコメント
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
2019 年 12 月 9 日
2 件のコメント
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 Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!