Calculating number in a string

SampleText.txt
file = 'SampleText.txt';
any assitance would be much appriciated, thanks.

 Accepted Answer

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 Comment

Worked a treat i thought i needed a loop thanks mate

Sign in to comment.

More Answers (1)

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 Comment

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

Sign in to comment.

Products

Release

R2021a

Asked:

on 30 Aug 2021

Edited:

on 5 Sep 2021

Community Treasure Hunt

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

Start Hunting!