Accessing cells of a cell array error

8 visualizaciones (últimos 30 días)
Brendan Rapp
Brendan Rapp el 1 de Jun. de 2023
Comentada: Brendan Rapp el 1 de Jun. de 2023
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 comentarios
Mathieu NOE
Mathieu NOE el 1 de Jun. de 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 ?
Brendan Rapp
Brendan Rapp el 1 de Jun. de 2023
Thank you!
I forgot about that. The datarpm{1} just comes from playing with the code. Works now

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by