Accessing cells of a cell array error
조회 수: 8 (최근 30일)
이전 댓글 표시
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
Mathieu NOE
2023년 6월 1일
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 ?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!