フィルターのクリア

fileDatastore using for loop and scatter

1 回表示 (過去 30 日間)
akk
akk 2021 年 10 月 24 日
回答済み: Ive J 2021 年 10 月 24 日
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

回答 (1 件)

Ive J
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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by