Can't get circshift to work for a string?

3 visualizzazioni (ultimi 30 giorni)
eel
eel il 15 Gen 2018
Commentato: Walter Roberson il 16 Gen 2018
I have an input that's converted to a string. I extract parts of the string until it's the numbers I need. I need to shift the numbers in this new string by 4, but the circshift function isn't working?
inputID = input('Please input an ID:');
createDate = input('Please input the creation date in MMDDYYYY format:');
str1 = string(inputID)
%str1 is equal to the numbers of the inputted ID
str2 = extractAfter(str1,5)
%str2 is the ID after the first 5 numbers have been removed
str3 = extractBefore(str2,9)
%str3 is the str2 after the last 9 numbers have been removed
%str3 results in the part of ID that is the supposed creation date
str4 = circshift(str3,4,1)
%str4 is str3 shifted so that it matches the format of the creation date
%takes a string of YYYYMMDD format and shifts it 4 characters to the right
%should end up MMDDYYYY format
I know it works through str3 step, but I'm not sure why the circshift isn't working. After running it, it continues to output str4 as exactly the same as str3.

Risposte (1)

Walter Roberson
Walter Roberson il 15 Gen 2018
circshift affects elements in an array. string() creates a string array, with each element being one string. It is the string array that you are circshift()'ing. To circshift the characters you will need to extract them from the string. For example,
str4 = string( circshift(str3{1}, 4, 1) );
  2 Commenti
eel
eel il 16 Gen 2018
I replaced my str4 line of code with this, and it still did not work, outputting the same thing it did before I tried this.
Walter Roberson
Walter Roberson il 16 Gen 2018
str4 = string( circshift(str3{1}, [1 4]) );

Accedi per commentare.

Categorie

Scopri di più su Characters and Strings 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!

Translated by