#Day71 #100DaysChallenge- Matlab Loops| Accessing Matrix Elements
#Day71-Accessing Matrix Elements
Task:
Write a code to access the matrix elements
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
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
Free Codes: youtube.com/castorclasses
No comments