How can I iterate through an array using a for loop?
I want to iterate through an array of file locations using a for loop.
My current code is something like this:
% Paths where the files are located
P1 = C:UsersmeDocuments\My Info
%Find excel files in path
%Pull data
% Write into a file
Now this code works great, but now I need to do the same thing to multiple paths while maintaining efficiency. To do this, I created an array of the paths I need to iterate through. How do I use a for loop to iterate through these paths? Here is what I have so far, but my code breaks when it tries to read the path because the text is not scalar when trying to use ‘dir’. Here is what I currently have:
% Paths where the files are located
P1 = C:UsersmeDocuments\My Info
P2 = C:UsersmeDocuments\My data
%Array of paths
Array = {‘P1, P2’}
for i = 1:length(Array)
%Find excel files in path
%Pull data
% Write into a fileI want to iterate through an array of file locations using a for loop.
My current code is something like this:
% Paths where the files are located
P1 = C:UsersmeDocuments\My Info
%Find excel files in path
%Pull data
% Write into a file
Now this code works great, but now I need to do the same thing to multiple paths while maintaining efficiency. To do this, I created an array of the paths I need to iterate through. How do I use a for loop to iterate through these paths? Here is what I have so far, but my code breaks when it tries to read the path because the text is not scalar when trying to use ‘dir’. Here is what I currently have:
% Paths where the files are located
P1 = C:UsersmeDocuments\My Info
P2 = C:UsersmeDocuments\My data
%Array of paths
Array = {‘P1, P2’}
for i = 1:length(Array)
%Find excel files in path
%Pull data
% Write into a file I want to iterate through an array of file locations using a for loop.
My current code is something like this:
% Paths where the files are located
P1 = C:UsersmeDocuments\My Info
%Find excel files in path
%Pull data
% Write into a file
Now this code works great, but now I need to do the same thing to multiple paths while maintaining efficiency. To do this, I created an array of the paths I need to iterate through. How do I use a for loop to iterate through these paths? Here is what I have so far, but my code breaks when it tries to read the path because the text is not scalar when trying to use ‘dir’. Here is what I currently have:
% Paths where the files are located
P1 = C:UsersmeDocuments\My Info
P2 = C:UsersmeDocuments\My data
%Array of paths
Array = {‘P1, P2’}
for i = 1:length(Array)
%Find excel files in path
%Pull data
% Write into a file matlab, for loop, array MATLAB Answers — New Questions