# Could I extract an specific column from a table and then use it in a loop without name it (variable)?

조회 수: 2(최근 30일)
DulceEien 2021년 8월 15일
댓글: DulceEien 2021년 8월 15일
I'm wondering if I can use directly the column (extracted from a matrix) inside the loop, for example or should I name if first because T1(:,8)(i) does not work
A = zeros(length(T1(:,7)),length(T2(:,7)));
for i=1:length(T1(:,7))
for ii=1:length(T2(:,7))
idx(i,ii) = ( abs((T1(:,8)(i)-T2(:,8)(i))))
end
end

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

### 채택된 답변

Walter Roberson 2021년 8월 15일
h1 = height(T1); h2 = height(T2);
A = zeros(h1, h2);
for i = 1 : h1
for ii = 1 : h2
A(i,ii) = abs(T1{i,8} - T2{i,8});
end
end
However... you might as well use
A = abs(T1{:,8} - T2{:,8}.');
with no loop, provided you have R2015b or later.
##### 댓글 수: 1표시숨기기 없음
DulceEien 2021년 8월 15일
thank you so much! (I put it in a loop because I want to use it for a conditional)

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

### Community Treasure Hunt

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

Start Hunting!