Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Column Removal

•Remove the nth column from input matrix A and return the resulting matrix in output B.

Example 1:

A = [1 2 3;

        4 5 6];

and

n = 2

then B is

[ 1 3

  4 6 ]

EXAMPLE 2:
A = 1:10;
n = 7;

B= [1 2 3 4 5 6 8 9 10];

MATLAB CODE:

clc
e=input('Enter the matrix:');
[x y]=size(e);
Y=[];
d=input('Enter the column you want to remove:');
for i=1:x
    for j=1:y
        if(j~=d)
            Y=[Y e(i,j)];
        end
    end
end
w=[];
t=1;
for i=1:x
    for j=1:y-1
        w(i,j)=Y(t);
        t=t+1;
    end
end
disp(w);

Explanation:


Sample Output:



Function:


function w=column_removal(e,d)
[x y]=size(e);
Y=[];
t=0;
k=1;
l=1;
for i=1:x
    for j=1:y
        if(j~=d)
            Y=[Y e(i,j)];
        end
    end
end
w=[];
t=1;
for i=1:x
    for j=1:y-1
        w(i,j)=Y(t);
        t=t+1;
    end
end
end

No comments

Popular Posts

Followers