Hi all, I created a struct using a for loop and need to extract values from it. So for instance, for field T with value = 728, it would produce the first row as shown in the photo.
Thanks
code
for CPR = 10:10:50
for BPR = 4:1:9
for FPR = 0.5:0.1:2
for TO4 = 500:200:1300
for m = 80:20:400
[ST,TSFC,T,] = turbofan(CPR,BPR,FPR,TO4,m)
Data(count).CPR = CPR;
Data(count).BPR = BPR;
Data(count).FPR = FPR;
Data(count).TO4 = TO4;
Data(count).ST = ST;
Data(count).TSFC = TSFC;
count = count+1;
end
end
end
end
end

2 Kommentare

Turlough Hughes
Turlough Hughes am 24 Apr. 2020
The first row as shown in the photo
So you want to find the index in field T where the value is close to 728 and then return values from all other fields corresponding to that index?
Joel Ogualiri
Joel Ogualiri am 24 Apr. 2020
Bearbeitet: Joel Ogualiri am 24 Apr. 2020
correct and then store them in a new struct with all the corresponding fields

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 24 Apr. 2020
Bearbeitet: Ameer Hamza am 24 Apr. 2020

0 Stimmen

You can read about details of struct array here: https://www.mathworks.com/help/matlab/matlab_prog/create-a-structure-array.html. To access the field T in the first row, you can access it like this
Data(1).T
Edit:
To extract the rows close to 728, you can use something like this
value = 728;
tolerance = 0.005; % tolerance of value around 728
idx = abs([s.T] - value) < tolerance;
new_Data = Data(idx);

6 Kommentare

Joel Ogualiri
Joel Ogualiri am 24 Apr. 2020
Bearbeitet: Joel Ogualiri am 24 Apr. 2020
Thanks but what I want is to have the struct save for only values of T = 728 in the for loop
Ameer Hamza
Ameer Hamza am 24 Apr. 2020
But the exact value of 728 does not exist. How much difference is allowed?
Joel Ogualiri
Joel Ogualiri am 24 Apr. 2020
Bearbeitet: Joel Ogualiri am 24 Apr. 2020
Maybe say values greater than 728 but less than 728.005. (I will increase the dataset later on thatll have values in this range.)
Ameer Hamza
Ameer Hamza am 24 Apr. 2020
Please check my updated answer.
Joel Ogualiri
Joel Ogualiri am 24 Apr. 2020
thanks a lot
Ameer Hamza
Ameer Hamza am 24 Apr. 2020
I am glad to be of help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by