Struggling with multiple csv files
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Stephen23
2023-5-31
编辑:Stephen23
2023-5-31
"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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!