Structs Help on indexing

2 Ansichten (letzte 30 Tage)
Hassan Hijazi
Hassan Hijazi am 8 Dez. 2020
Beantwortet: Ameer Hamza am 8 Dez. 2020
I have a struct with 7 feilds called climate.info
one of the feilds is City, and withing this feild there are hundreds of cities and the climate at certain times.
Therefore there are hundreds of entries of the same city at different times.
Is it possible to get the values of all the times of only that one specific city.
  2 Kommentare
Hassan Hijazi
Hassan Hijazi am 8 Dez. 2020
This is an example of the struct, and I want all the data values that are only for the city of abidjan
Walter Roberson
Walter Roberson am 8 Dez. 2020
Is climate.info.City a struct array ("hundreds of entries") that has fields that give the city name and fields that give the climate information ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Ameer Hamza
Ameer Hamza am 8 Dez. 2020
Try something like this
city_name = 'Abidjan';
idx = contains({climate.info.name}, city_name);
city_data = climate.info(idx)

Kategorien

Mehr zu Structures 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