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!