Getting variables for different files
이전 댓글 표시
I am trying to load multiple files and extract respective data from them. I have managed to successfully load the multiple files, but I am having trouble assigning each unique variable to them. I have uploaded 2 sample files, contained within a folder.
This means that I manage to loop through for the different areas, but each time the loop processes, the variables A,B,C changes.
I want it such that A1,B1,C1 is for the first area, A2,B2,C2 is for the second area and so on...how do I go about doing this? I tried A(k),B(k)C(k) but it did not work.
inFile = 'filepath\weather\';
location={'savannah-ga_temp','newyork-ny_temp','acadia-me_temp','boston-ma_temp','charleston-sc_temp','kingston-ri_temp'};
for k=1:length(location)
loc = strcat(location(k), '.csv');
tempfile = string(loc)
combinename = strcat (inFile,tempfile)
% Loading file
[A,B,C] = textread(combinename,'%*s %f %f %*f %f','headerlines',2,'delimiter',',','emptyvalue',NaN);
end
댓글 수: 1
"I want it such that A1,B1,C1 is for the first area, A2,B2,C2 is for the second area and so on..."
Magically changing/accessing variable names is one way that beginners force themselves into writing slow, complex, buggy code. Read this to know why:
You should just use indexing and some cell arrays. Indexing is simple, neat, and very efficient. Unlike what you are trying to do. Indexing is exactly what the MATLAB documentation shows:
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!