Using 'if' to conduct specific matrix cell operations
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Matt J
2021년 11월 19일
P2=ones(size(P));
subset=(P<1);
P2(subset)=1-Pfailgrid(subset);
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!