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 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by