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

Search This Blog

#Day71 #100DaysChallenge- Matlab Loops| Accessing Matrix Elements

#Day71-Accessing Matrix Elements

Task:

Write a code to access the matrix elements

x =

     1     2     3     4     5
     1     2     3     4     5
     1     2     3     4     5
y =

     1     1     1
     2     2     2
     3     3     3
     4     4     4
     5     5     5

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab code


function y= accessingmatrix(x)
[m,n]=size(x);

for i=1:1:n
    for j=1:1:m
        y(i,j)=x(j,i);
       
    end
end
end

Sample Input and Output

>> x=[1,2,3,4,5;1,2,3,4,5;1,2,3,4,5]

x =

     1     2     3     4     5
     1     2     3     4     5
     1     2     3     4     5

>>y= accessingmatrix(x)

y =

     1     1     1
     2     2     2
     3     3     3
     4     4     4
     5     5     5

Click here for Video Description



Live Support: t.me/matlabirawen







No comments

Popular Posts