MATLAB: How to load data files from different folder using for loop

for loopsprintf

Hello,
I am trying to load all my data into two structs using a for loop. Below is a copy of my code so far, the issue is I am recieiving is a warning followed by an error. The warning is, 'Warning: Escaped character '\ ' is not valid. See 'doc sprintf' for supported special characters.', and the error is, 'Error using load Unable to read file 'Z:\RobertFlores\MATLAB'. Input cannot be a directory.'.
I think the reason why I am getting a warning is that the program is trying to find a command for \B, like \n is new line. However, I do not know if just addeing a space in between the forward slashes would fix the warning or not.
The error, I have no idea to fix. I am using a code similar to the one in this link: https://www.mathworks.com/matlabcentral/answers/178647-how-to-load-different-data-files-in-a-for-loop
If anyone can help me resolve my issue, it will be greatly appreciated, thank you.
Sincerely,
Robert Flores
CODE:
clc, clear, close all
% Data of Interest
for i = [12:19,31,34,41-93]
filename1 = sprintf('Z:\ BARB\ TestData\ ShockData_July2018\ Time_Histories_R2\ test0%d_filt_time.mat',i)
filename2 = sprintf('Z:\ BARB\ TestData\ ShockData_July2018\ Time_Histories_R2\ test0%d_raw_time.mat',i)
S1{i} = load(filename1)
S2{i} = load(filename2)
end

Best Answer

Use \\ instead of \
Related Question