find column from list then save cell

조회 수: 1 (최근 30일)
Vincent I
Vincent I 2014년 6월 23일
댓글: Vincent I 2014년 6월 24일
Hi,
I have two cells:
A = {'One','Four','Five'};
B = {'One','Two','Three','Four','Five';1 2 3 4 5;6 7 8 9 10};
Find A in B = C
C = {'One','Four','Five';1 4 5;6 9 10}
As shown above, I would like find the columns from A in B and the save them to another cell C without using either a for or while loop.
Cell A can have different numbers so whats shown above its not always the same.
Thank you

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 6월 23일
C = B(:,ismember(B(1,:),A))

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 6월 23일
A = {'One','Four','Five'};
B = {'One','Two','Three','Four','Five';1 2 3 4 5;6 7 8 9 10};
If you work with tables
BB=cell2table(B(2:end,:),'VariableNames',B(1,:))
C=BB(:,A)
  댓글 수: 1
Vincent I
Vincent I 2014년 6월 24일
cell2table did not work for me. I'm sure with some tweaking i could have worked.
Thank you very much for your help

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by