MATLAB Answers


how to find rows and columns without using size

Asked by Hanwool Yun on 14 Sep 2019
Latest activity Commented on by Adam Danz
on 15 Sep 2019
Introductory MATLAB course, haven't covered loops and such yet. I'm curious how to find rows + columns of an array without using size fxn? Obv numel()/length() give you rows + columns, but they don't tell you which is which. What to do next?


Show 1 older comment
I'm not allowed to use the size fxn.
What is the actual text of the assignment, not your interpretation of it?
An assignment that asks you to find the size of a matrix without using the size function would be completely absurd. Sure you can find all sorts of roundabout ways of doing it, none of which would teach you anything useful and all of them requiring more advanced knowledge than the size function.
^^ my thoughts exactly.

Sign in to comment.

2 Answers

Answer by Bruno Luong
on 14 Sep 2019
Edited by Bruno Luong
on 14 Sep 2019

for 2D array
if p==0
r = A(1,:);
n = 0;
m = numel(A*zeros(0,1));
m = 0;
m = numel(zeros(1,0)*A);
m = numel(A(:,1));
n = p/m;


unfortunately we haven't covered loops yet, is there any way to do this with basics, like using length and numel and indexing?
loop? which loop?

Sign in to comment.

Answer by Bruno Luong
on 15 Sep 2019

[numel(prod(A,2)) numel(prod(A,1))] % prod instead of sum for a change


Sign in to comment.