What is the alternative for startsWith function in Matlab 2013?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
TF = startsWith(names_cell,pattern)
I have a snippet of code written above. The names_cell is a cell array and pattern is a string array.
I need to find an alternative in Matlab R2013b, where there is no such a function.
1 Kommentar
Antworten (2)
Walter Roberson
am 8 Nov. 2019
temp = arrayfun(@(S) strncmp(names_cell, S, length(S)), pattern, 'uniform', 0);
nd = ndims(temp{1}) + 1;
TF = or(cat(nd, temp{:}), nd);
This is designed to work no matter how many dimensions names_cell has. The output should be the same size as names_cell is.
The code can be simplified for the more common case where pattern is a character vector or scalar string array.
2 Kommentare
Walter Roberson
am 11 Nov. 2019
What is size(names_cell) and size(pattern) ?
At one point some functions shifted from giving a row vector result in some cases to giving a column vector result instead; I would need to test further on that point. I am not sure I have R2013b still installed though.
Akansha Saxena
am 21 Okt. 2020
TF = cellfun(@(x) strncmpi(x, pattern, length(pattern)),names_cell);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!