New variable for each xlsread from a different file
이전 댓글 표시
First time using Matlab so I have no clue about this.
For my thesis, I have a number of excel files from collecting data. The tables in each file are the same dimensions representing the same data type (freq vs dB).
I want to import these to Matlab so I can graph them individually and also then average them together (since they are just test runs of the same set-up).
In the loop, I want it to spit out variables SPL_1, SPL_2, SPL_3 etc.
Right now this is my code. It gathers the file list fine. But I can't work out how to create a new SPL variable for each time it reads from an excel file.
%====IMPORT ACOUSTIC TEST DATA FROM N63 COMFORT EXCEL .CSV FILES====%
%State constant variables%
alpha = 1;
s_source = 2;
a_recieve = 3;
spl_IL_= 4;
%Frequency Column
freq = xlsread(freq_data,'A2:A102');
%Import Data - Excel Loop%
Files = dir('*.xlsx');
fnames = {Files.name};
filename = fnames';
%Determine Size for Loop
D = size(filename);
Numloop = D(1,1);
%Loop to Create Paths for each file
for i = 1:Numloop
run = filename(i,1)
excel_sheet = run{1}
SPL_1 = xlsread(excel_sheet,'B2:B102')
end
댓글 수: 3
Stephen23
2018년 10월 30일
"In the loop, I want it to spit out variables SPL_1, SPL_2, SPL_3 etc."
Do NOT do that. Magically accessing variable names is one wy that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
It is much simpler and much more efficient to just use indexing, exactly as the MATLAB documentation shows:
Harrison Schipke
2018년 10월 30일
채택된 답변
추가 답변 (1개)
madhan ravi
2018년 10월 30일
0 개 추천
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!