fileDatastore using for loop and scatter
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I am trying to load multiple .csv files from a folder (file1.csv, file2.csv, etc). Then I would like to plot specifc variables from each table onto the same plot. I can only get my code to plot one file though. I am not great with for loops...
fds = fileDatastore('*.csv', 'ReadFcn', @importdata)
fullFileNames = fds.Files
numFiles = length(fullFileNames)
% Loop over all files reading them in and plotting them.
for k = 1 : numFiles
fprintf('Now reading file %s\n', fullFileNames{k});
T = readtable('file4.csv');
scatter3( -T.Long, T.Lat, T.Depth_Meter_, 30, T.Temperature_Celsius_);hold on;
end
댓글 수: 0
답변 (1개)
Ive J
2021년 10월 24일
You are not even reading your csv files; you just read the same file file4.csv over and over! Try this:
fds = fileDatastore('*.csv', 'ReadFcn', @readtable);
fullFileNames = fds.Files
numFiles = length(fullFileNames)
% Loop over all files reading them in and plotting them.
figure; hold on
for k = 1:numel(fds.Files)
fprintf('Now reading file %s\n', fds.Files{k});
T = read(fds);
scatter3( -T.Long, T.Lat, T.Depth_Meter_, 30, T.Temperature_Celsius_);
end
hold off
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!