Accessing cells of a cell array error

8 vues (au cours des 30 derniers jours)
Brendan Rapp
Brendan Rapp le 1 Juin 2023
Commenté : Brendan Rapp le 1 Juin 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 commentaires
Mathieu NOE
Mathieu NOE le 1 Juin 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 le 1 Juin 2023
Thank you!
I forgot about that. The datarpm{1} just comes from playing with the code. Works now

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by