fileDatastore using for loop and scatter

4 Ansichten (letzte 30 Tage)
akk
akk am 24 Okt. 2021
Beantwortet: Ive J am 24 Okt. 2021
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

Antworten (1)

Ive J
Ive J am 24 Okt. 2021
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

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by