fprintf length of vector

6 次查看(过去 30 天)
Arashdeep Dhillon
Arashdeep Dhillon 2019-4-17
评论: Guillaume 2019-4-23
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?

回答(1 个)

Adam Danz
Adam Danz 2019-4-17
编辑:Adam Danz 2019-4-23
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 个评论
Guillaume
Guillaume 2019-4-23
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by