Converting 9 digit number into a string

I have a (1675x 1) number matrix. Each numbers are 9 digit number. I want convert this no into string. When I am giving the num2str command it is giving me (1675 x 9) matrix, but I want to get a (1675 x 1) matrix. How can I do that?

3 件のコメント

Joseph Cheng
Joseph Cheng 2017 年 4 月 5 日
why do you need it in a 1675x1 matrix? because that is not going to work with a string and matrix format as each digit is a index as a string. it can work as a cell array but i do not see any benefit for putting it in such a format.
Sadia
Sadia 2017 年 4 月 6 日
編集済み: Walter Roberson 2017 年 4 月 6 日
I wanted to run the following code:
T = array2table (raw (2:end,[2,1,4,17,18]));
T.Properties.VariableNames = {'Station' 'Date' 'PM' 'Lat' 'Long'};
T2 = unstack(T, 'PM', 'Date', 'GroupingVariables', 'Station')
Then it is showing the following error
Error using tabular/unstack (line 212)
Unable to group rows using unique values of the table variable 'Station'. UNIQUE returned an error.
Error in PM25 (line 20)
T2 = unstack(T, 'PM', 'Date', 'GroupingVariables', 'Station')
Caused by:
Error using cell/unique (line 85)
Input A must be a cell array of character vectors.
That's why I wanted to convert this station from number to char. But my station values are 9 digit numbers and it is not giving me one character for one station.
MD SAROWER HOSSAIN
MD SAROWER HOSSAIN 2021 年 8 月 17 日
my roll : 191001520

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2017 年 4 月 5 日

0 投票

If you have R2016b or later, you can use compose()
Result = compose('%d', YourMatrix);
Otherwise you have to use a cell array if you want individual entries. For example,
Result = cellstr( int2str(YourMatrix) );

2 件のコメント

Walter Roberson
Walter Roberson 2017 年 4 月 6 日
You should be using cell2table() rather than array2table() so that you can combine values of different types.
Sadia
Sadia 2017 年 4 月 7 日
Thanks a lot.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by