% Set a dummy array content:
name = {'Joe'; 'Elisa'; 'John'};
age = [30; 10; 25];
weigth = [100; 150; 180];
% Set 'select_collumns' array:
% The index (1) reference to 'name' array
% The index (2) reference to 'age' array
% The index (3) reference to 'weigth' array
selected = [1, 0, 1];
% Create a table with only select collumns: (1) Name and (3) Weigth:
How could I do it?
% Exemple:
table(name, weigth);
The main ideia is pass a 'select array' that will produce a table with only the select collumns.
How can I do it?

 채택된 답변

Guillaume
Guillaume 2019년 1월 8일

0 개 추천

1. Create the full table first, however you were going to create it:
name = {'Joe'; 'Elisa'; 'John'};
age = [30; 10; 25];
weigth = [100; 150; 180]; %note that weigth is mispelled, should be weight
t = table(name, age, weight)
2. use logical indexing to select the columns you want:
selected = [1, 0, 1];
selected = logical(selected);
%or create it directly as logical:
%selected = [true, false, true];
filteredtable = t(:, selected) %only keep selected columns

댓글 수: 1

Nycholas Maia
Nycholas Maia 2019년 1월 8일
Thank you so much Guillaume for your quick response!

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Genomics and Next Generation Sequencing에 대해 자세히 알아보기

제품

릴리스

R2018b

태그

질문:

2019년 1월 8일

댓글:

2019년 1월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by