how to convert a character into string

I read a line from notepad. It is in char. It need to be converted to string for conversion
To read a line
fid1=fopen('M:\decompiler\dct.txt','r')
C_line = fgetl(fid1)
to read a word
instruction = string(inst(14:19))
The read word is a char. I need it in string

 Accepted Answer

Walter Roberson
Walter Roberson on 6 Jan 2016
Edited: Walter Roberson on 6 Jan 2016
MATLAB strings are row vectors of characters. There is no MATLAB string data type.

5 Comments

I need to convert that char into string. Iam attaching the profiled data, 0x0B55 0x5000 movf 0x00,w,0 144 0x0B56 0x2600 addwf 0x00,f,0 144 0x0B58 0x3602 rlcf 0x02,f,0 144 0x0B59 0x3603 rlcf 0x03,f,0 144
I need to read the mneumonics alone from each line. Eg. movf from first line,addwf from second line, rlcf from third line.
how to read that words alone
Walter Roberson's Answer tells you that there is no fundamental MATLAB class "string", only the class "char". This means a string is a char array. You can read it for yourself:
Please show us exact input and output examples of what you want to achieve, then we can help you more easily.
Hey folks, I'd like a little more clarification on this. I'm on MATLAB 2016a, which appears to be directly before string became an actual datatype. When I assign a character array to a variable, e.g.
comPort = 'COM4';
and call
isstring(comPort);
MATLAB returns logical false. The reason why I'm curious as to this behavior is that I am trying to default to a specific serial port if the user doesn't provide one in a function, but MATLAB seems to treat
serial('COM4');
differently to
serial(comPort);
R2016a did not have isstring() . It did have isstr()
The string data type was added in R2016b, which is when isstring() appeared. isstring() tests for the string data type, not for character vectors, so isstring('COM4') would be expected to be false because 'COM4' is a character vector rather than a string object.
MATLAB may treat serial('COM4') differently than comPort='COM4'; serial(comPort); when generating code, including possibly for MATLAB Function Block of a Simulink model. There are a number of functions where code generation requires that some of the parameters be constants rather than computed. For example code generation needs constants when what the code generation phase is doing is effectively running the function ahead of time and generating static code for the resulting array, such as can happen with building filters or communications codes. On the other hand, MATLAB Coder does not support serial() at all.
Thanks for the info!

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!