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
KSSV
KSSV 2021년 6월 8일
I kept it for checking later whether columns deleted properly or not. You may remove this.

댓글을 달려면 로그인하십시오.

추가 답변 (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