i have a vector and i want to convert it in to single cell aray.

조회 수: 7 (최근 30일)
rishika yadav
rishika yadav 2022년 7월 6일
댓글: Star Strider 2022년 7월 7일
A = [12 33 44 55 66]
I want to convert it in cell = { 12, 33,44,55,66}

답변 (2개)

Star Strider
Star Strider 2022년 7월 6일
I am not certain what result you want.
Two options —
A = [12 33 44 55 66]
A = 1×5
12 33 44 55 66
B = num2cell(A)
B = 1×5 cell array
{[12]} {[33]} {[44]} {[55]} {[66]}
B = {A}
B = 1×1 cell array
{[12 33 44 55 66]}
.
  댓글 수: 2
rishika yadav
rishika yadav 2022년 7월 7일
i want to convert it like thia and apply unique propertiy as unique(A) to count the class
A= {'12',' 33', ' 44','55', ' 66'}
Star Strider
Star Strider 2022년 7월 7일
Try this —
A = [12 33 44 55 66];
B = cellstr(string(A))
B = 1×5 cell array
{'12'} {'33'} {'44'} {'55'} {'66'}
Au = unique(A)
Au = 1×5
12 33 44 55 66
Bu = unique(B)
Bu = 1×5 cell array
{'12'} {'33'} {'44'} {'55'} {'66'}
You can use unique with both of these.
I have no idea what ‘count the class’ means.
.

댓글을 달려면 로그인하십시오.


Sanyam
Sanyam 2022년 7월 6일
You can create an empty cell of the size of your vector: x = cell(size(A))
Then itererate over all the elements of your vector and assign them correspondingly to your cell variable
In your example, it code would look like:
for i = 1:size(A,2)
x{i} = A(i)
end
Hope that helps! Thanks!
  댓글 수: 1
rishika yadav
rishika yadav 2022년 7월 7일
i need to convert a single cell array of this A vector.
A= {'12',' 33', ' 44','55', ' 66'}

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by