Filter löschen
Filter löschen

How to extract a subtable by rownames?

4 Ansichten (letzte 30 Tage)
JFz
JFz am 28 Okt. 2016
Kommentiert: JFz am 28 Okt. 2016
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

Akzeptierte Antwort

Steven Lord
Steven Lord am 28 Okt. 2016
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

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by