Calculating number in a string

3 visualizaciones (últimos 30 días)
Ben Hischar
Ben Hischar el 30 de Ag. de 2021
Editada: Ben Hischar el 5 de Sept. de 2021
SampleText.txt
file = 'SampleText.txt';
any assitance would be much appriciated, thanks.

Respuesta aceptada

Wan Ji
Wan Ji el 30 de Ag. de 2021
Then do following code
for i = 1:1:nLines
fprintf('%d: %s\n',i,fileStr{i})
end
fprintf('This file has %d lines', nLines)
  1 comentario
Ben Hischar
Ben Hischar el 30 de Ag. de 2021
Worked a treat i thought i needed a loop thanks mate

Iniciar sesión para comentar.

Más respuestas (1)

Mathieu NOE
Mathieu NOE el 30 de Ag. de 2021
hello
you can add these lines to your code :
for ci = 1:nLines
if size(fileStr{ci})>0
disp([num2str(ci) ' : ' fileStr{ci}]);
end
end
  1 comentario
Mathieu NOE
Mathieu NOE el 30 de Ag. de 2021
FYI, the if statement line is to not display empty cells , but if you wish to have it, just remove that statement;
all the best

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by