ERROR: Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts) is not supported. Use a row subscript and a variable subscript.

Hello experts. I am doing a coding for two tables to find the common factor for a new table. Undamaged table have 269 datas whereas damaged table have 317 datas. I want MATLAB to find the same X Location (column 2) and extract to new table. Below are the coding. However i got error, kindly help to resolve my problem.
% load tables (damaged & undamaged)
x_undamaged = undamaged(:,2);
x_damaged = damaged(:,2);
deforamtion_damaged = damaged(:,5);
deforamtion_undamaged = undamaged(:,5);
%To compare x nodes and extract corresponding deformation for the node
i=1
j=1
for i=1:317
if x_damaged(i) == x_undamaged(i)
new(j,1)= x_damaged(i);
new(j,2)= deformation_damaged(i);
new(j,3) = deformation_undamaged(i);
i=i+1;
j=j+1
else
i=i+1
end
end

댓글 수: 2

New coding below since previously got typos.
x_undamaged = undamaged(:,2);
x_damaged = damaged(:,2);
deforamtion_damaged = damaged(:,5);
deforamtion_undamaged = undamaged(:,5);
i=1
j=1
for i=1:317
if x_damaged(i) == x_undamaged(i)
new(j,1)= x_damaged(i);
new(j,2)= deforamtion_damaged(i);
new(j,3) = deforamtion_undamaged(i);
i=i+1;
j=j+1
else
i=i+1
end
end
i =
1
j =
1
When you do x_damaged = damaged(:,2) it will generate a table with 1 variable. Hence when you try to index into x_damaged later on as x_damaged(i), you get the error, since you need 2 indices to subscript into a table. It looks like you just want to extract that vector. So you can use brace indexing for that
x_damaged = damaged{:,2}
After this the code should work fine.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

댓글:

2021년 1월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by