Accessing cells of a cell array error
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everybody,
I want to modify the previous code of my stored data by accessing a cell array I've made. However, every time I want to access the second Element MATLAB states that my Cell array (datarpm) is a 1x1 Cell and there is no second cell to access. if I comment it out, MATLAB generates the cell array as a 1x19(which is expected) and I am able to access the second cell via the command window but not in the code section. Does anybody see my error?
Code below:
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)
fnm = fullfile(Drpm,files(i).name);
datarpm{i} = readmatrix(fnm);
y = num2cell(datarpm, 1);
thelp = y{1};
t = thelp{1}(:, 1);
x = datarpm{1};
% x2 = datarpm{2}; %% This is where the problem occurs. Error: Index exceeds the number of array elements. Index must not exceed 1.
rpm = x(:, 2);
end
2 Kommentare
Mathieu NOE
am 1 Jun. 2023
at the first iteration of your loop ,you have only genrated datarpm{1} , datarpm{2} does not yet exist
this throw the error message
I wonder why you need to have access to datarpm{1} and datarpm{1} at each iteration step ?
Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!