MATLAB Count size of matrix without size function in matlab

AI Thread Summary
To track the size of a matrix without using the "size" function, one can utilize alternative methods. For instance, multiplying a specific row or column by zero, such as A(1, :) * 0 or A(:, 1) * 0, can be effective in determining dimensions. In the example provided, creating a zero matrix A with dimensions 5x6 allows for the use of the length function to find the number of columns, yielding the result of 6. This approach demonstrates a practical workaround for obtaining matrix dimensions without directly using the size function.
hsong9
Messages
71
Reaction score
1
I need to keep track of the size of the matrix myself.
This means I can't use "size" function.
Is it possible?
For example,

A is a 5 x 5 matrix. I need to create a vector x=[0,0,0,0,0].
It should be just
x = zeros(size(A,1),1); %or length(A)

but I need to check the size of A matrix without size function.

Could anyone give me hints?

Thank you
 
Physics news on Phys.org
Wouldn't A(1, :)*0 or A(:, 1)*0 work?
 
INPUT
A= zeros(5,6) % Just as an Example
Cols=length(A) % Returns # of columns in A

OUTPUT
A= [0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0]
Cols=6

does that help?
 

Similar threads

Back
Top