Accessing cells of a cell array error
8 views (last 30 days)
Show older comments
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 Comments
Mathieu NOE
on 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 ?
Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!