What is the difference between input of cell array {[Hi]} and {'Hi'}

4 ビュー (過去 30 日間)
Lucrezia Cester
Lucrezia Cester 2020 年 9 月 8 日
回答済み: Walter Roberson 2020 年 9 月 8 日
As the title says,
I have a cell array which contains data in this format
{[Hi]}
but I want to turn it to {'Hi'} so that I can turn the data into a categorical format.
Any suggestions on how to do this?
  5 件のコメント
Adam Danz
Adam Danz 2020 年 9 月 8 日
編集済み: Adam Danz 2020 年 9 月 8 日
" I want to turn it to {'Hi'} so that I can turn the data into a categorical format."
It sounds like the data are already categorical. For example,
c = categorical({'Hi'});
{c, 'Hi'}
% ans =
% 1×2 cell array
% {[Hi]} {'Hi'}
OMKARAM RAJESHWARA RAJU
OMKARAM RAJESHWARA RAJU 2020 年 9 月 8 日
編集済み: OMKARAM RAJESHWARA RAJU 2020 年 9 月 8 日
1. from the question: what is difference between {[ Hi ]} , { 'Hi' } ..?
{[ Hi ]} ==> this will produce an error called :::: unrecoginized function variable
instead you have to use :::: { [ 'Hi' ] }
there is no difference between A1 = {'Hi'} and A2 = {['Hi']}
both are 1 * 1 cell arrays
even interms of memory : both will occupy the same 112 bytes of overhead
(or in newest versions 108 bytes of overhead)
but the difference comes when we add next element
A3 = {'Hi' 'Fi'}
A4 = {['Hi' 'Fi']}
A3 is a cell array of size = 1 * 1 ==> {'HiFi'} ==> concatenation
A4 is a cell size = 1 * 2 ==> 'Hi' 'Fi' ==> 2 seperate cells
interms of memory: both have different memory allocation accordingly
2 . CATEGORICAL
the concept of categorical will come only when the input data type has multiple elements.
categorical is a data type that assigns values to a finite set of discrete categories, such as High, Med, and Low. These categories can have a mathematical ordering that you specify, such as High > Med > Low
please go through the documentation of categorical
hope your doubt is cleared...!

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

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 9 月 8 日
If you have something that is displaying as
{[Hi]}
then it is a cell array that contains categorical data. If all of the entries in the same cell are scalar categorical, then you can use cell2mat() to convert into an array of categorical. Or if that fails, then [NameOfCell{:}]

カテゴリ

Help Center および File ExchangeCategorical Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by