Struggling with multiple csv files

조회 수: 15 (최근 30일)
Brendan Rapp
Brendan Rapp 2023년 5월 31일
편집: Stephen23 2023년 5월 31일
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!

채택된 답변

Stephen23
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
  댓글 수: 1
Brendan Rapp
Brendan Rapp 2023년 5월 31일
Worked great! Thank you for your help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by