MATLAB Answers

Finding a Number in a random array

2 views (last 30 days)
Josiah Miles
Josiah Miles on 7 Oct 2019
Edited: Kevin Phung on 7 Oct 2019
So I am given the code p1pA=magic(7).
How would I use Matlab to find the number in the fourth row and sixth column?
Also how would I find the twentieth number?

  0 Comments

Sign in to comment.

Accepted Answer

Kevin Phung
Kevin Phung on 7 Oct 2019
Edited: Kevin Phung on 7 Oct 2019
How would I use Matlab to find the number in the fourth row and sixth column?
p1pA=magic(7);
p1pA(4,6) %The syntax is p1Pa(row,column)
Also how would I find the twentieth number?
p1pA(20)
% if just 1 index provided, the indices go column by column.
%Ex :[1 4 7]
% [2 5 8]
% [3 6 9]

  0 Comments

Sign in to comment.

More Answers (1)

Turlough Hughes
Turlough Hughes on 7 Oct 2019
Have a look at the following documentation and scroll down to the part about indexing matrices with two subscripts. For your second question I believe you are looking for linear indexing which is the next section.

  0 Comments

Sign in to comment.

Sign in to answer this question.