fprintf length of vector

4 views (last 30 days)
Arashdeep Dhillon
Arashdeep Dhillon on 17 Apr 2019
Commented: Guillaume on 23 Apr 2019
how do i print the length of a vector?? so i have a vector V = [4,9,-3,12,0,-9,15,17,25,-6,4,10,-2,15] and i got its length by L = length (V) now how do i print the length?

Answers (1)

Adam Danz
Adam Danz on 17 Apr 2019
Edited: Adam Danz on 23 Apr 2019
fprintf('Length of vector is %d\n', length(V))
The " %d " specifies that the number to be printed is an integer which should always be the output of length().
The " \n " specifies that a new line should be started after this text.
  1 Comment
Guillaume
Guillaume on 23 Apr 2019
Note: another option that may be more intuitive for beginners
disp("Length of vector is " + length(V))
I'd recommend using numel rather than length. Many people misuse length.

Sign in to comment.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!