MATLAB Answers

how to do Shifting of text

4 views (last 30 days)
ANAND VISHAL
ANAND VISHAL on 27 Feb 2020
Commented: Stephan on 28 Feb 2020
Assume this is text line:
volatile uint8_T AtomcMduleCnt_Z_Pt = 7U;/* Atomic Module Count in Pack */
I have to shift this line by 4 position:
volatile uint8_T @ AtomcMduleCnt_Z_Pt = 7U;/* Atomic Module Count in Pack */
so how to do shifting of text in matlab?

  0 Comments

Sign in to comment.

Answers (1)

Stephan
Stephan on 27 Feb 2020
Edited: Stephan on 27 Feb 2020
A = "volatile uint8_T AtomcMduleCnt_Z_Pt = 7U;/* Atomic Module Count in Pack */"
B = insertAfter(A,"uint8_T"," @")
A =
"volatile uint8_T AtomcMduleCnt_Z_Pt = 7U;/* Atomic Module Count in Pack */"
B =
"volatile uint8_T @ AtomcMduleCnt_Z_Pt = 7U;/* Atomic Module Count in Pack */"

  4 Comments

Show 1 older comment
Stephan
Stephan on 27 Feb 2020
Then you can use replace:
A = ["volatile uint8_T AtomcMduleCnt_Z_Pt = 7U;/* Atomic Module Count in Pack */"
"volatile real32_T AutoWakeUpBalncDlyT_T_Pt = 3.0F;/* Delay time to distinguish to go to sleep. */"
"volatile real32_T AvgChrgOcUWrtSoc_U_Yy[29] = { 410.05F, 413.78F, 416.49F,"
"volatile real32_B AvgDschgOcUAt2Pc_U_Pt = 317.49F;/* Average pack nominal voltage at 2% SOC at 25 degC at 2 C-rate. */"]
B = replace(A, ["uint8_T " "real32_T " "real32_B "],["uint8_T Rom_" "real32_T Rom_" "real32_B Rom_"])
A =
4×1 string array
"volatile uint8_T AtomcMduleCnt_Z_Pt = 7U;/* Atomic Module Count in Pack */"
"volatile real32_T AutoWakeUpBalncDlyT_T_Pt = 3.0F;/* Delay time to distinguish to go to sleep. */"
"volatile real32_T AvgChrgOcUWrtSoc_U_Yy[29] = { 410.05F, 413.78F, 416.49F,"
"volatile real32_B AvgDschgOcUAt2Pc_U_Pt = 317.49F;/* Average pack nominal voltage at 2% SOC at 25 degC at 2 C-rate. */"
B =
4×1 string array
"volatile uint8_T Rom_AtomcMduleCnt_Z_Pt = 7U;/* Atomic Module Count in Pack */"
"volatile real32_T Rom_AutoWakeUpBalncDlyT_T_Pt = 3.0F;/* Delay time to distinguish to go to sleep. */"
"volatile real32_T Rom_AvgChrgOcUWrtSoc_U_Yy[29] = { 410.05F, 413.78F, 416.49F,"
"volatile real32_B Rom_AvgDschgOcUAt2Pc_U_Pt = 317.49F;/* Average pack nominal voltage at 2% SOC at 25 degC at 2 C-rate. */"
ANAND VISHAL
ANAND VISHAL on 27 Feb 2020
Sir this is text file and we cannot alter the text file.
This is the input file and output file we have to write m script in such a way without alter input we get output file.
Stephan
Stephan on 28 Feb 2020
A = fileread('Input_file.txt');
B = replace(A, ["uint8_T " "real32_T " "real32_B "],["uint8_T Rom_" "real32_T Rom_" "real32_B Rom_"]);
fileID = fopen('Output_File.txt','w');
fprintf(fileID, B);
fclose(fileID);

Sign in to comment.

Tags

No tags entered yet.

Products