Command Window, display line numbers?

9 visualizaciones (últimos 30 días)
Joshua Scicluna
Joshua Scicluna el 14 de En. de 2021
Respondida: Walter Roberson el 30 de Ag. de 2024
Hi. Is it possible to make matlab print line numbers in the command window? like;
Thanks!
1 %something%
2 %something%
3 %something%
>>

Respuestas (2)

Harsh Sharma
Harsh Sharma el 30 de Ag. de 2024
Hi Joshua,
There is no method to configure command window in such a manner that the line number is shown corresponding to every line in output automatically, but you can achieve that my printing the line numbers on your own using the manual script. Here’s an example code to achieve that –
output = {
"%something%",
"%something%",
"%something%"
};
% Loop through each line and print with line numbers
for i = 1:length(output)
fprintf('%d: %s\n', i, output{i});
end
Hope this is what you were trying to achieve.

Walter Roberson
Walter Roberson el 30 de Ag. de 2024
In a fairly limited sense:
You can get line numbers of a file that you are displaying. Use dbtype . For example
dbtype which.m
1 %WHICH Locate functions and files. 2 % WHICH ITEM displays the full path for ITEM. ITEM can include a partial 3 % path, complete path, relative path, or no path. ITEM must be on the 4 % search path or in the current folder. 5 % 6 % If ITEM is a Simulink model, a MATLAB app file, or a MATLAB function or 7 % script in a MATLAB code file, then WHICH displays the full path for the 8 % corresponding file. 9 % 10 % If ITEM is a method in a loaded Java class, then WHICH displays the 11 % package, class, and method name for that method. 12 % 13 % If ITEM is a workspace variable, then WHICH displays a message 14 % identifying ITEM as a variable. 15 % 16 % If ITEM is a file name with a specified extension, then WHICH displays 17 % the full path of ITEM. 18 % 19 % If ITEM is an overloaded function or method, then WHICH ITEM returns 20 % only the path of the first function or method found. 21 % 22 % WHICH FUN1 in FUN2 displays the path to function FUN1 that is called by 23 % file FUN2. Use this syntax to determine whether a local function is 24 % being called instead of a function on the path. This syntax does not 25 % locate nested functions. 26 % 27 % WHICH ___ -ALL displays the paths to all items on the MATLAB path with 28 % the requested name. Such items include methods of instantiated classes. 29 % You can use -ALL with the input arguments of any of the previous 30 % syntaxes. 31 % 32 % S = WHICH(ITEM) returns the full path for ITEM in the character vector, S. 33 % 34 % S = WHICH(FUN1,'IN',FUN2) returns the path to function FUN1 that is 35 % called by file FUN2. Use this syntax to determine whether a local 36 % function is being called instead of a function on the path. This syntax 37 % does not locate nested functions. 38 % 39 % S = WHICH(___,'-ALL') returns the results of WHICH in the character vector or 40 % cell array of character vectors, S. You can use this syntax with any of the input 41 % arguments in the previous syntax group. Each row of cell array S 42 % identifies a function. The functions are in order of precedence, unless 43 % they are shadowed. Among shadowed functions, you should not rely on the 44 % order of the functions in S. 45 % 46 % For more information about function precedence order, see the MATLAB 47 % documentation. 48 % 49 % See also DIR, HELP, WHO, WHAT, EXIST, LOOKFOR, FILEPARTS, MFILENAME, 50 % PATH, TYPE 51 52 % Copyright 1984-2018 The MathWorks, Inc. Built-in function.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by