String and character array not properly printing
Show older comments
I am trying to write a prompt for input from the user in a subfunction. This prompt will be dependent upon the name of the files they have loaded in another subfunction. I can get Matlab to correctly write the string (as shown when I look at the variable while debugging) using the following code,
function GraphIt (filenamestr)
promptopt=strings(1,length(filenamestr)); %preallocating
prompt=sprintf('Which file do you want to graph from? (Please input number)'); %first line of prompt
for i=1:length(filenamestr) %Writing string
promptopt=sprintf(' %d. %s',i,filenamestr(i));
prompt=strvcat(prompt,promptopt);
end
funcstr=input(prompt); %User input
However I cannot get the string to properly print via fprintf or the prompt of the input. I have tried using the char command (with \n at the end of each line) instead of strvcat to write the text as a character array but I still have the same problem.
Please note that the string has characters such as ()-, in it.
For reference the string prints as:
W h12i..c h0L .if1Bi NlMMe B B dLmoDi -cyIro-ou1e 2lw0ea cnpttor lotydo(e L gi6rBVaN pMchBy )cf lr(io1nm.g?5. t(mxPLtl) e am si en i i nb pa ut th nt ue ms bt e, r )i n s i d e g l o v e b o x , t e f l o n c a p , P t m i c r o e l e c t r o d e , 6 V 5 0 c y c l e s , 0 . 0 1 V s . t x t W h12i..c h0L .if1Bi NlMMe B B dLmoDi -cyIro-ou1e 2lw0ea cnpttor lotydo(e L gi6rBVaN pMchBy )cf lr(io1nm.g?5. t(mxPLtl) e am si en i i nb pa ut th nt ue ms bt e, r )i n s i d e g l o v e b o x , t e f l o n c a p , P t m i c r o e l e c t r o d e , 6 V 5 0 c y c l e s , 0 . 0 1 V s . t x t
when it should be:
Which file do you want to graph from? (Please input number)
1. 0.1 M BLD-I-120 poly(LiBNMB) (1.5 mL) mini bath test, inside glovebox, teflon cap, Pt microelectrode, 6 V 50 cycles, 0.01Vs.txt
2. LiBNMB microelectrode 6V cycling.txt
Thanks for your help!
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!