Count size of matrix without size function in matlab

Click For Summary
SUMMARY

The discussion focuses on determining the size of a matrix in MATLAB without using the built-in "size" function. A user seeks alternative methods to track the dimensions of a matrix, specifically a 5x5 matrix, while creating a corresponding vector. Suggestions include using matrix multiplication with zero, such as A(1, :)*0 or A(:, 1)*0, to derive the number of columns. The example provided demonstrates initializing a zero matrix and using the length function to obtain the number of columns.

PREREQUISITES
  • Understanding of MATLAB syntax and operations
  • Familiarity with matrix manipulation in MATLAB
  • Knowledge of vector initialization in MATLAB
  • Basic concepts of matrix dimensions and indexing
NEXT STEPS
  • Explore MATLAB matrix operations and their implications
  • Learn about alternative methods for matrix dimension retrieval in MATLAB
  • Investigate the use of logical indexing in MATLAB
  • Study MATLAB's built-in functions for matrix manipulation
USEFUL FOR

This discussion is beneficial for MATLAB users, particularly those involved in numerical computing, data analysis, and algorithm development who need to manage matrix dimensions without relying on built-in functions.

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

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K