Effacer les filtres
Effacer les filtres

fileDatastore using for loop and scatter

1 vue (au cours des 30 derniers jours)
akk
akk le 24 Oct 2021
Réponse apportée : Ive J le 24 Oct 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

Réponses (1)

Ive J
Ive J le 24 Oct 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

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by