if you run F Zero you will get [2 5], I want to delete the column number 2 and 5 from the Matrix W, but the problem is when I'm deleting the columns it deletes number 2 and 6

1 次查看(过去 30 天)
clc;
clear;
W=rand(6)
Pt=10;
Pn=[2 7 3 2 8 4];
P = waterfill(Pt,Pn);
F_Zero=find(~P) %Find Zeros
%% delete the columns
if (~isempty(F_Zero)) %There is Zeros (not empty)
for i=1:length(F_Zero) % Loop to Set Columns to Zeros
C_Zero=F_Zero(i);
W(:,C_Zero) = []
end
end

采纳的回答

KSSV
KSSV 2021-6-8
When you are using a loop the ddimension of W changes and it removes the column in the newly obtained W. You need not to use loop. remove columns at once.
clc;
clear;
W=rand(6) ;
Pt=10;
Pn=[2 7 3 2 8 4];
P = waterfill(Pt,Pn);
F_Zero=find(~P) %Find Zeros
%% delete the columns
if (~isempty(F_Zero)) %There is Zeros (not empty)
W(:,F_Zero) = [] ;
end
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by