Alternatives to substr without Stateflow?
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Erik Taurus
il 9 Mag 2020
Commentato: Erik Taurus
il 12 Mag 2020
I was trying to make a sub string and searched and found this.
However this seem to require Stateflow, which I don't have...
Trying to make my own way(implementation?) using
string = "This should really be in the MatLab core!";
%convert to character array
b = convertStringsToChars(string);
ba = length(b);
%get index of "in the"
k = strfind(b,"in the");
stringbuilder = "";
%start the loop from k
for cIx = k:ba
%sprintf because spaces will be ignored otherwise
stringbuilder = strcat(stringbuilder,sprintf("%s",b(cIx)));
end
disp(stringbuilder);
Result:
in the MatLab core!
---
Is there another way?
0 Commenti
Risposta accettata
Ameer Hamza
il 9 Mag 2020
Modificato: Ameer Hamza
il 9 Mag 2020
char arrays support indexing. Also, string is the name of MATLAB built-in function, so I named the name of the variable to 'str'
str = "This should really be in the MatLab core!";
%convert to character array
b = char(str); % you can simply use char()
ba = length(b);
%get index of "in the"
k = strfind(b,"in the");
stringbuilder = b(k:end);
stringbuilder = string(stringbuilder); % convert back to string
Result
>> stringbuilder
stringbuilder =
"in the MatLab core!"
3 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!