I'm taking a course that uses matlab, and for one assignment, we need to write a function that, among other things, counts the number of rows and columns in any given numeric matrix. The thing is that we're not allowed to use(adsbygoogle = window.adsbygoogle || []).push({}); anybuilt-in functions. No x = size(mat). No length(mat). It all has to be done with loops.

I was thinking of writing 2 while loops; one to count the number of columns and one to count the number of rows. The only problem is that I have no idea how to check whether or not a specified row or column exists. I tried the 'exist' function, but that will only tell me if the matrix exists.

any help is appreciated.

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Counting the number of rows/cols in a matrix with Matlab

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**