How can I identify the maximum value in a column and then grab specific cells in the same row as that value?
Mostra commenti meno recenti
In the script below, I am bringing in data from the attached spreadsheet and reorganizing it as necessary. After getting to the point where I have the load cases (LC1-LC7) the way I need, I need to identify the maximum resultant in the "Resultant" column, then pull out the cells associated w/ that value, in the same row that correspond with the columns titled: Structure Loads Vert. (lbs), Structure Loads Trans. (lbs) and Structure Loads Long. (lbs). In essence, I should end up with seven (7) 1x3 matrices (or tables). I will then need to save each of the 7 matrices/tables for later with a specific name (i.e. LC1_1_1, LC2_1_1, etc.). I'll then want to repeat when the SetNo.= 3 and Phase No.=1 (result matrices LC1_3_1, LC2_3_1, etc.) and so on.
data = readtable('34231_Future Loads.xlsx','VariableNamingRule','preserve');
data.resultant = sqrt(data.('Structure Loads Vert. (lbs)').^2 + data.('Structure Loads Trans. (lbs)').^2 + data.('Structure Loads Long. (lbs)').^2);
SetNo=[1 3 9 9 9 10 10 10 45 46 49 49 49 50 50 50 51 51 51 52 52 52 53 54 57 58 59 60];
PhaseNo=[1 1 1 2 3 1 2 3 1 1 1 2 3 1 2 3 1 2 3 1 2 3 1 1 1 1 1 1];
SetNo=[1 3 9 9 9 10 10 10 45 46 49 49 49 50 50 50 51 51 51 52 52 52 53 54 57 58 59 60];
PhaseNo=[1 1 1 2 3 1 2 3 1 1 1 2 3 1 2 3 1 2 3 1 2 3 1 1 1 1 1 1];
%NOTE: I could try to use a for loop here to loop through all set & phases
chosenSetNo = 1;
chosenPhaseNo = 1;
idx = data.('Set No.') == chosenSetNo & data.('Phase No.') == chosenPhaseNo;
data_1 = data(idx,:);
LC1 = data_1([],:);
LC2 = data_1([],:);
LC3 = data_1([],:);
LC4 = data_1([],:);
LC5 = data_1([],:);
LC6 = data_1([],:);
LC7 = data_1([],:);
%METHOD 1: LOGICAL INDEXING METHOD | This method helps save memory and
%possible errors.
LC1 = data_1(contains(data_1{:,4},"NESC 250B"|"NESC Insul"),:);
LC2 = data_1(contains(data_1{:,4},"Hurr"|"RULE 250C Insul"),:);
LC3 = data_1(contains(data_1{:,4},"Rule 250D"|"RULE 250D Insul NA+"|"RULE 250D Insul NA-"),:);
LC4 = data_1(contains(data_1{:,4},"Normal"),:);
LC5 = data_1(contains(data_1{:,4},"2%"),:);
LC6 = data_1(contains(data_1{:,4},"NESC 250B NL-, DE"|"NESC 250B NR-,DE"|"NESC 250B BI-, DE"),:);
LC7 = data_1(contains(data_1{:,4},"Rule 250D BI-, DE"|"Rule 250D NL-, DE"|"Rule 250D NR-, DE"),:);
%Delete the extra rows in LC1 & LC3 that apply to the full break cases for NESC 250B & Rule 250D
LC1([9,10,11],:) = [];
LC3([7,8,9],:) = [];
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Programming in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!