Borrar filtros
Borrar filtros

How to get a string array from a vector structure with a common field?

69 visualizaciones (últimos 30 días)
Nadav Auerbach
Nadav Auerbach el 22 de Mayo de 2020
Respondida: Quad el 22 de Mayo de 2020
Hi,
I have a 1x48 struct (called 'results') with a common field: 'Names'. I would like to build a 1x48 cell of all the names corresponding to the structures - results(1).Names, results(2).Names, results(3).Names etc.
Here is an example:
results(1).Names = 'Chris';
results(2).Names = 'Daniel';
results(3).Names = 'Matt';
Is there a way to build a cell:
all_names = {'Chriss', 'Daniel', 'Matt'};
is a way that does not require to build a loop?
I have tried
all_names = results.Names; %this gives back the value results(1).Names
and
all_names = [results.Names] %this gives me back a character vector combining all the strings together.
Thanks,

Respuestas (1)

Quad
Quad el 22 de Mayo de 2020
all_names = {results(:).Names}

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by