필터 지우기
필터 지우기

Changing values in a table

조회 수: 11 (최근 30일)
Wesso
Wesso 2021년 1월 14일
답변: Walter Roberson 2021년 1월 14일
M is a table where if a specific column in M is =1 the respective rows in the subsequent columns (starting at cl1 and ending at cl2) should be 1 as well. I tried something like this but it didn't work
X=table2array(M(:,cl1-1)); % where cl1 is the first column that i want to change its values
x0=find(X==1);
for i=1:length(x0)
for j=cl1:cl2 %cl2 is the last column that I want to change
M(x0(i),j)=1;
end
end
Any help is greatly appreciated

채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 14일
No loop should be needed.
X = M{:,cl1-1};
M{X == 1, cl1:cl2} = 1;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by