arrays - Unable to open a file with uigetfile in Matlab -
i building code lets user open files.
reference = warndlg('choose files analysis.'); uiwait(reference); filenames2 = uigetfile('./*.txt','multiselect', 'on'); if ~iscell(filenames2) filenames2 = {filenames2}; % force cell array of strings end numberoffiles = numel(filenames2); data = importdata(filenames2{i},delimiterin,headerlinesin);
when run code, prompts show up, press ok, , nothing happens. code stops, telling me :
error using importdata (line 137) unable open file. error in freqvschampb_no_spec (line 119) data=importdata(filenames2{1},delimiterin,headerlinesin);
i don't have opportunity select file. cellarray stays empty showed in following image.
matlab can't find file have selected. variable filenames2
contains name of file, not full path. if don't provide full path importdata
, search whatever file name provide on matlab path, , if can't find it error see.
try - i'm doing single selection ease of description, can similar multiple selection.
[filename, pathname] = uigetfile('*.txt'); fullnamewithpath = fullfile(pathname, filename); importdata(fullnamewithpath)
fullfile
useful, inserts correct character between pathname
, filename
(\
on windows, /
on unix).