I have a problem with indexing in nested for loop.
3 ビュー (過去 30 日間)
古いコメントを表示
I have a problem with indexing in nested for loop. I am trying to create a matrix where the outer loop for the columns index and the inner loop for the rows index. The problem it is saying ' Index in position 2 exceeds array bounds. Index must not exceed 6' also ' Error in username (line 166)
if femur_6d (rows,columns)~=0' .
Please see the code below :
motion_data = csvread("hip_test_6d.csv",1,1);
hip_6d = motion_data(:,1:6);
femur_6d = motion_data(:,7:12);
for columns=1:size(femur_6d)
for rows=1:size(femur_6d)
if femur_6d (rows,columns)~=0
corrected_femur (rows,columns)=femur_6d (rows,columns);
elseif femur_6d (rows,columns)==0
corrected_femur(rows,columns)=femur_6d (rows-3,columns);
end
end
end
0 件のコメント
回答 (2 件)
Chunru
2021 年 12 月 6 日
for columns=1:size(femur_6d, 2) % number of columns
for rows=1:size(femur_6d, 1) % number of rows
0 件のコメント
Mathieu NOE
2021 年 12 月 6 日
hello
my suggestion
motion_data = csvread("hip_test_6d.csv",1,1);
hip_6d = motion_data(:,1:6);
femur_6d = motion_data(:,7:12);
%% added %%
[m,n] = size(femur_6d); % rows and columns size
%%%%%%%%%%
for columns=1:n
for rows=1:m
if femur_6d (rows,columns)~=0
corrected_femur (rows,columns)=femur_6d (rows,columns);
elseif femur_6d (rows,columns)==0
corrected_femur(rows,columns)=femur_6d (rows-3,columns);
end
end
end
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!