Importing single and multiple files
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I want to import single as well as multiple files, by first code i am able to import multiple files but if i select single file it shows error, please help me to get the result. I have done some changes in code 2 but still error is there.
* * * * * * * * * * * * * * * |* *Item one**|***************
if true
[fileList, folder] = uigetfile('*.txt',...
'Find the File to Import', ...
'Multiselect', 'on')
for k = 1:length(fileList)
baseFileName = fileList{k}
fullFileName = fullfile(folder, baseFileName)
fprintf(1, 'Now reading %s\n', fullFileName)
end
- * * * * * * * * * * * * * * * * * * * * * * * * * * * *Item two*****************************
if true
[fileList, folder] = uigetfile('*.txt',...
'Find the File to Import', ...
'Multiselect', 'on')
for k = 1:length(fileList)
if k==1
baseFileName = fileList
fullFileName = fullfile(folder, baseFileName);
fprintf(1, 'Now reading %s\n',fullFileName );
raw_data = importdata(fullFileName)
s = raw_data.data
else
baseFileName = fileList{k}
fullFileName = fullfile(folder, baseFileName);
fprintf(1, 'Now reading %s\n',fullFileName );
raw_data = importdata(fullFileName)
s = raw_data.data
end
var = s(:,3)
s(:,3)= s(:,1)
s(:,1)= var
s = sortrows(s)
end
0 Kommentare
Akzeptierte Antwort
Jan
am 10 Feb. 2016
[fileList, folder] = uigetfile('*.txt',...
'Find the File to Import', ...
'Multiselect', 'on');
fileList = cellstr(fileList);
for k = 1:length(fileList)
...
Now fileList is a cell string in all cases.
2 Kommentare
Weitere Antworten (1)
Ingrid
am 10 Feb. 2016
is this what you try to achieve?
if true
[fileList, folder] = uigetfile('*.txt',...
'Find the File to Import', ...
'Multiselect', 'on')
if length(fileList) == 1
baseFileName = fileList
fullFileName = fullfile(folder, baseFileName);
fprintf(1, 'Now reading %s\n',fullFileName );
raw_data = importdata(fullFileName)
s = raw_data.data
else
for k = 1:length(fileList)
baseFileName = fileList{k}
fullFileName = fullfile(folder, baseFileName);
fprintf(1, 'Now reading %s\n',fullFileName );
raw_data = importdata(fullFileName)
s{k} = raw_data.data
end
s = [s{:}];
end
var = s(:,3)
s(:,3)= s(:,1)
s(:,1)= var
s = sortrows(s)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Environment and Settings 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!