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 view (last 30 days)
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

Accepted Answer

KSSV
KSSV on 8 Jun 2021
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 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!