Loading multiple data folders and call them in a For Loop
조회 수: 4 (최근 30일)
이전 댓글 표시
I have 13 data files named data24,data30......to data99
I want to read all the data sets by calling them one for one in a for loop to extract data from each file. By selecting one vector of each file
I have tried some num2str, text2double commands but nothing seems to get it
i have:
data24 = readtable('c4-40-steady_15_pressure24.dat');
data30 = readtable('c4-40-steady_15_pressure30.dat');
data35 = readtable('c4-40-steady_15_pressure35.dat');
data40 = readtable('c4-40-steady_15_pressure40.dat');
data50 = readtable('c4-40-steady_15_pressure50.dat');
data60 = readtable('c4-40-steady_15_pressure60.dat');
data70 = readtable('c4-40-steady_15_pressure70.dat');
data80 = readtable('c4-40-steady_15_pressure80.dat');
data85 = readtable('c4-40-steady_15_pressure85.dat');
data90 = readtable('c4-40-steady_15_pressure90.dat');
data95 = readtable('c4-40-steady_15_pressure95.dat');
data98 = readtable('c4-40-steady_15_pressure98.dat');
data99 = readtable('c4-40-steady_15_pressure99.dat');
Section = [24 30 35 40 50 60 70 80 85 90 95 98 99]; %Sections along blade
for i = Section
for j = 1:length(Section)
x_pos(j,:) = table2array(data('here is my problem, i want the numbers to be read')(2:62,1));
end
end
댓글 수: 0
답변 (2개)
Mathieu NOE
2021년 11월 19일
hello
see example below for excel files - simply adapt the inner code to read your data and file extension
also you need to load this excellent FEX submission
clc
clearvars
fileDir = pwd;
S = dir(fullfile(fileDir,'data00*.xlsx')); % get list of data files in directory
S = natsortfiles(S); % sort file names into natural order , see :
%(https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
for k = 1:length(S)
S(k).data = importdata( fullfile(fileDir, S(k).name));
end
댓글 수: 1
Stephen23
2021년 11월 19일
Note that 'data' was part of the variable names. Matching the filenames requires a file pattern something like
'c4-40-steady_15_pressure*.dat'
Rik
2021년 11월 19일
Your mistake was in your naming of the variables. If you can guarantee they are always integers, you can do something like this (otherwise you will need ismember with a lookup table):
Section = [24 30 35 40 50 60 70 80 85 90 95 98 99]; %Sections along blade
data=cell(1,max(Section));
for n=1:numel(Section)
ind=Section(n);
filename=sprintf('c4-40-steady_15_pressure%d.dat',ind);
data{ind}readtable(filename);
end
for i = Section
for j = 1:length(Section)
x_pos(j,:) = table2array(data{j}(2:62,1));
% ^ not sure j is what you need
end
end
Also, avoid length, use numel or size instead.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!