MATLAB: How to load files in order if statement I am looking for How to load files in order please find attached file If i = 1:5 data = importdata('RR.data.(i)'); That has error Best Answer Use either of the methods shown in the documentation:https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.htmlFor example:N = 2; % number of filesC = cell(1,N);for k = 1:N F = sprintf('RR.data.%u',k); C{k} = dlmread(F);endM = vertcat(C{:});Giving:>> MM = 0 850 0 0 850 0 Related SolutionsMATLAB: How to import the image with the number. Luckily those dates use an ISO 8601 date format, so you can simply import them sorted into character order:S = dir('*.tif')F = sort({S.name});N = numel(F);C = cell(1,N);for k = 1:N C{k} = imread(F{k});endSee: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html MATLAB: Read 1000’s .csv files and concatenate them N = 1760;C = cell(1,N);for k = 1:N F = sprintf('d0.%d.csv',k-1); C{k} = csvread(F,2);endand after that either vertcat or horzcat:M = horzcat(C{:})M = vertcat(C{:})Alternatively you could preallocate a numeric array of the correct size:N = 1760;M = nan(2500,N);for k = 1:N F = sprintf('d0.%d.csv',k-1); M(:,k) = csvread(F,2);endhttps://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html Related QuestionSaving a csv file as a .mat fileStoring values from a for loop into a new variable
Best Answer