Info
This question is closed. Reopen it to edit or answer.
strange behavior in selecting/loading file
1 view (last 30 days)
Show older comments
At the beginning of a script, I bring up a dialog that allows me to select a directory (=group), and one of the *.mat files contained in it. Name and path of the selected file are returned in the variables fname and pname.
Here's a very odd behavior: when I run the script, the file does not get read in, and fname or pname = 0; it's as if the code jumped over line 4. When I go into debugging mode and step through that part of the code, there is no problem: it brings me to the selected directory and lets me chose a file which is then processed further; pname and fname get filled correctly, and assembled as correct file path & name in pp2. What gives?
k = menu('Choose a group','G01','G02','G03','G04');
what2 = ['G01';'G02';'G03';'G04'];
group = what2(k,:);
[fname, pname] = uigetfile(['C:\Data\exp1\' group '\post_step1\????r.mat']);
pp2=[pname fname];
eval(['load ' pp2 ';']);
0 Comments
Answers (1)
Image Analyst
on 4 Apr 2015
Try this:
button = menu('Choose a group','G01','G02','G03','G04')
what2 = ['G01';'G02';'G03';'G04'];
group = what2(button,:);
filePattern = sprintf('C:/Data/exp1/%s/post_step1/????r.mat', group)
[baseFileName, folder] = uigetfile(filePattern)
if baseFileName ~= 0
fullFileName = fullfile(folder, baseFileName)
storedStructure = load(fullFileName)
end
Note: use forward slashes in sprintf() - forward slashes work just fine in Windows and Linux.
2 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!