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.

Help for instructions matrix in Matlab

Status
Not open for further replies.

medanisse

Newbie level 6
Joined
Sep 29, 2010
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,398
Hello,

Can you give me an instruction with matlab which allows me to resize a matrix, keep only the odd or even elements of the matrix

Example
transform the matrix a =[1 2 3 4 5 6 7 8 9 10]
to a =[2 4 6 8 10]
 

Hello. Please try the following code mscript

Code:
clear all;
close all;

A =[1 2 3 4 5 6 7 8 9 10]

%Even matrix index counter
eCnt = 1;

%Odd matrix index counter
oCnt = 1;

for i = 1:length(A)
   
    %if value is even
    if(mod(A(i),2) == 0)
      A_even(eCnt) = A(i);
      eCnt = eCnt + 1;
    
    
    else
        A_odd(oCnt) = A(i);
        oCnt = oCnt+1;
    end
end

A_even
A_odd

output:

Code:
A_even =

     2     4     6     8    10


A_odd =

     1     3     5     7     9
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top