フィルターのクリア

How to extract a subtable by rownames?

4 ビュー (過去 30 日間)
JFz
JFz 2016 年 10 月 28 日
コメント済み: JFz 2016 年 10 月 28 日
Hi,
I have a table of 10 columns and one column represent last names. I would like to extract all the rows that belong to one last name. How to do that? Thanks in advance.
Jennifer

採用された回答

Steven Lord
Steven Lord 2016 年 10 月 28 日
Modifying the example on this documentation page a bit:
% Make a patients table
load patients
patients = table(Age,Gender,Height,Weight,Smoker,...
'RowNames',LastName);
% Give each patient a random first name
bloggers = {'Cleve'; 'Loren'; 'Guy'; 'Steve'; 'Stuart'; 'Hans'};
n = numel(bloggers);
p = size(patients, 1);
patients.FirstName = bloggers (randi([1 n], p, 1));
% Retrieve all patients named Steve using logical indexing
patientsNamedSteve = patients(strcmp(patients.FirstName, 'Steve'), :);
% There shouldn't be any patients named Aaron; check using logical indexing
patientsNamedAaron = patients(strcmp(patients.FirstName, 'Aaron'), :)
isempty(patientsNamedAaron) % true
  1 件のコメント
JFz
JFz 2016 年 10 月 28 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by