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!