Using 'if' to conduct specific matrix cell operations
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Daniel McDonald
am 19 Nov. 2021
Kommentiert: Daniel McDonald
am 19 Nov. 2021
I'm trying to use the 'if' function on specific matrix cells to create a new matrix then find the product of that matrix, which will ultimately be used to minimuze a risk function. So far I have Points 'P' and the associated failure 'Pfailgrid', both 1x200 matrices, but regardless of my changes in P (which are binary), y = 0. Any tips would be appreciated, I'm sure I haven't clarified well enough so please let me know if I can do so. Thank you.
function y = DistObj(P)
Pfailgrid = readmatrix('PfailColumn.xlsx'); %1x200
P = readmatrix('Points.xlsx'); %1x200
if P(:,1) <= 1
P2(:,1) = 1-Pfailgrid(:,1);
else
P2(:,1) = 1;
end
y = prod(P2); % makes 1x200 = Ppass
end
0 Kommentare
Akzeptierte Antwort
Matt J
am 19 Nov. 2021
P2=ones(size(P));
subset=(P<1);
P2(subset)=1-Pfailgrid(subset);
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!