how to concatenate string and number
Mostra commenti meno recenti
Hello ,
I want to concatenate string and number in for loop
requestID = Req_Check;
for k = 1 : 10
requestID = requestID +1;
end
I am expecting requestID after for loop like Req_Check_1, Req_Check_2 ...Req_Check_10
How can I do this?
1 Commento
Amir Moslemi
il 2 Mag 2021
use "strcat" such that in each iteration convert number to string by "num2str" and eventually strcat(s1,s2). s1 your str and s2 your number(converted to string)
Risposta accettata
Più risposte (2)
cesar silva
il 18 Nov 2019
19 voti
People like to make all complicated...
Concatenate 2 words
a='hi';
b='you'
c=[a b]
Concatenate word + number
a = num2str(2)
b = 'you'
c = [b a] or... if you want... c = [b '_' a]
will give you: you2 or you_2
SIMPLICITY IS SO SEXY...
3 Commenti
Victor Matzkin
il 16 Dic 2019
If you think that's simple or intuitive, you're going to freak out when you discver another programming language..
Daniel Posadas
il 13 Ago 2020
I'm agree with you, this one helped me out easy and fast... as a sofware engineer I hate when my programmers want to make simple things as if they were very elaborated, wasting resources. Thanks
Bogdan -Ervin
il 2 Giu 2023
It doesn't give me a single string. It gives me 2 strings for c=[b a] and 3 strings for c=[b '_' a].
MathWorks Support Team
il 11 Giu 2024
requestID = "Req_Check"
requestIDs = requestID + "_" + (1:10)'
Categorie
Scopri di più su Common Operations in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!