How can i return a value based on mutliple fields?

1 Ansicht (letzte 30 Tage)
Emma Kuttler
Emma Kuttler am 10 Nov. 2019
Kommentiert: Emma Kuttler am 11 Nov. 2019
I have a structure named N2, with three fields - Components, PowerConsequences, and ICTConsequences.
>>N2 =
struct with fields:
Components: [43660×2 double]
PowerConsequences: [43660×1 double]
ICTConsequences: [43660×1 double]
>> fieldnames(N2)
ans =
3×1 cell array
{'Components' }
{'PowerConsequences'}
{'ICTConsequences' }
The components field is a vector with two columns, so N2.Components returns a list like this. It describes the combination of 2 components in a system, and the other fields describe effects.
290 296
291 292
291 293
291 294
291 295
291 296
292 293
And so on. How do i return a value in the field PowerConsequences or ICTConsequences based on two specific values in the field Components - ie for the values (290,296) in the Components field, how do i return the value in the PowerConsequences Field?

Akzeptierte Antwort

Shubham Gupta
Shubham Gupta am 11 Nov. 2019
Bearbeitet: Shubham Gupta am 11 Nov. 2019
Try:
id = find(N2.Components(:,1) == 290 & N2.Components(:,2) == 296);
PowerConsequences_out = N2.PowerConsequences(id);
ICTConsequences_out = N2.ICTConsequences(id);
I hope it helps.
  1 Kommentar
Emma Kuttler
Emma Kuttler am 11 Nov. 2019
What if i wanted to return the average of everything with a specific value in the components field? Like the value in the field PowerConsequences for all combinations of components that contain component 1? Would it be something like this?
>> mean(id = find(N2.Components(:,1)=1)
My end goal is to take the average of all PowerConsequences for all combinations that include Component 1, Component 2, etc

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Communitys

Weitere Antworten in  Power Electronics Control

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by