How to create a for loop comparing excel vectors to (sub)folders?
Show older comments
I've been trying to create a loop confirming that each string vector in the excel file (Avanto_Sub2.xls) is equal to the string vector provided in the folder '\test_script_matlab\', named P1,P2,P3,P4 and P5 (foldername). The issue is that I only get "no match" displayed instead of the expected "match" and I don't understand why. When running the script without the loop function I do get the match, so it seems it has to do with the loop. Thanks in advance for your reply.
% code
start_path = fullfile(matlabroot, '\Users\m.laansma\AppData\Roaming\MathWorks\MATLAB\R2012a');
cd '\test_script_matlab\' ;
[~,~,filenames] = xlsread('Avanto_Sub2.xls','A1:A5');
disp(filenames)
ARCHDIR = '\test_script_matlab\';
SUBJIDS = { 'P1' ; 'P2' ; 'P3' ; 'P4' ; 'P5' } ;
disp(SUBJIDS)
for i = 1:length(SUBJIDS)
tst_id = SUBJIDS{i} ;
disp(tst_id) ;
WORKDIR = ARCHDIR ;
if isequal(tst_id,filenames)
disp('match')
else disp('no match') ;
end
end
disp 'finished'
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!