Struggling with multiple csv files
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello everyone,
I am new to working with reading files in matlab. So, my automated testing generated multiple files like "... rpm_Variation1", "... rpm_Variation2" and so on. Now I came up with the following code:
clear all;
close all;
clc
%%First part just to test if it works
file = 'C:\Users\Brendan\OneDrive\Masterarbeit_prädiktive_Stromregler\Modelle\01_Parameter\01_Ld\rpm\01_Ld_FCS_MPCCC_rpm_Variation1.csv';
A = readmatrix(file);
x = num2cell(A, 1)
t = x{1}
%%Second part for reading in multiple files
Drpm = 'C:\Users\Brendan\OneDrive\Masterarbeit_prädiktive_Stromregler\Modelle\01_Parameter\01_Ld\rpm';
files = dir (fullfile(Drpm, '*.csv'));
for i = 1:length('files')
datarpm = readmatrix(files(i).name);
end
The code above gave me following errors:
Error using readmatrix (line 158)
Unable to find or open '01_Ld_FCS_MPCCC_rpm_Variation1.csv'. Check the path and filename or file permissions.
Error in Variation_Ld (line 31) datarpm = readmatrix(files(i).name);
Unfortunately, I don't have an idea how to correct these errors. Does anyone have an idea?
Thank you in advance!
0 commentaires
Réponse acceptée
Stephen23
le 31 Mai 2023
Modifié(e) : Stephen23
le 31 Mai 2023
"I don't have an idea how to correct these errors. Does anyone have an idea?"
The error message already tells you how: "Check the path and filename or file permissions."
You told DIR, but forgot to tell READMATRIX to look in the correct location.
Drpm = 'C:\Users\Brendan\OneDrive\Masterarbeit_prädiktive_Stromregler\Modelle\01_Parameter\01_Ld\rpm';
files = dir(fullfile(Drpm, '*.csv'));
for i = 1:numel(files) % fixed bug
fnm = fullfile(Drpm,files(i).name); % added
datarpm = readmatrix(fnm); % modified
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Whos dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!