MATLAB Answers

How to import files from an outside folder?

11 views (last 30 days)
ARP
ARP on 30 Apr 2018
Answered: Fangjun Jiang on 30 Apr 2018
I am stuck with the following. I am designing a GUI, which should access files from a different folder as the one where the GUI is located, that is the main matlab folder.
The GUI works fine when I place the files on the main folder, but fails when taking the files from outside folder. The data files are '.txt'. I made an import function that reads the files and separates the column values, as time and data. Only one time array is needed.
This is what I am trying:
folder = uigetdir('C:\Users\..\data folder');
files = dir(fullfile(folder, '*.txt'));
NF = length(files) ;
for i = 1:length(files)
A = import_AB_function(files(i).name) ;
data{i} = A;
Ampl_S {i} = (data{:, i}(:,end));
end
time = data{1, 1}(:,1);
Amplitudes_all = cell2mat(Ampl_S);
I can tell that import function is not able to interpret outside files from the main folder, but I can not see the way around it.
Any help please?
Thanks guys
%################################# Error output:
Error using textscan Invalid file identifier. Use fopen to generate a valid file identifier.
Error in import_AB_function (line 36) dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'TextType', 'string', 'EmptyValue', NaN, 'HeaderLines', startRow(1)-1, 'ReturnOnError', false, 'EndOfLine', '\r\n');
Error in please (line 22) A = import_AB_function(files(i).name) ;

  0 Comments

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 30 Apr 2018
A = import_AB_function(fullfile(folder,files(i).name))

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by