MATLAB Answers

0

I want to print the dot number that contains the text character.

Asked by Muhendisleksi on 20 Feb 2018
Latest activity Edited by Walter Roberson
on 20 Feb 2018
clear
clc
NN = str2mat('s23;s24');
for i = 1:2
name{i}= sprintf('%d. Point', NN(i))
end
I tried something like that but I could not do it.

  2 Comments

For the cases i=1 and i=2 what would your desired output be?
i=1 >>> s23. Point
i=2 >>> s24. Point

Sign in to comment.

Tags

1 Answer

Answer by Walter Roberson
on 20 Feb 2018
Edited by Walter Roberson
on 20 Feb 2018
 Accepted Answer

NN_split = strsplit(NN, ';');
for i = 1 : 2
name{i} = sprintf('%s. Point', NN_split{i});
end
Mind you, I would not have initialized NN that way in the first place unless there was good reason to:
NN = {'s23', 's24'};
for i = 1 : 2
name{i} = sprintf('%s. Point', NN{i]);
end
or more simply
NN = {'s23', 's24'};
name = strcat(NN, '. Point');
with no loop.

  0 Comments

Sign in to comment.