Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Matlab matrix - delete elements

Status
Not open for further replies.

stepan89

Newbie level 4
Joined
Aug 16, 2010
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Czech Republic
Activity points
1,339
Hello everyone,

Can someone help me please with this code?
I have vectors (coordinates) x = [1 1 2 3 5 6 1 1 5] and y = [2 3 6 8 4 1 1 1 5]
If I plot them, everything's ok, it works...

plot(x, y, 'bo') for example...

Now I would like to delete some elemets, to be accurate: If the x OR y is less than or equal to 2 I would like to delete this elemet and plot without these coordinates ... I hope you do understand :)

Code:
x = [1 1 2 3 5 6 1 1 5];
y = [2 3 6 8 4 1 1 1 5];
numberOfElements = numel(x);

for i=1:1:numberOfElements
     if (x(i) > 3) || (y(i) > 3)
        x(i) = [];
        y(i) = [];
      end;
end;
plot(x,y,'bo');

That is my idea, but it doesn't work.

Please help if you can,
Thank you,

stepan89
 

I think you can simply generate two new vectors that include all the element having x AND y greater than 2:
-------------------------------------
x = [1 1 2 3 5 6 1 1 1];
y = [2 3 6 8 4 1 1 1 1];
h = [];
k = [];
numberOfElements = length(x);

for i=1:1:numberOfElements,
if (x(i) > 2) & (y(i) >2)
h = [h x(i)];
k = [k y(i)];
end
end
plot(h,k,'bo');
-------------------------------------

Regards
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top