필터 지우기
필터 지우기

Character Vector to Character Cell Array

조회 수: 1 (최근 30일)
Leah Ettensohn
Leah Ettensohn 2020년 8월 18일
답변: SAA 2020년 8월 19일
I have a logical character vector, a, with the dimensions 5580x1 (example below). I want to convert a into a 5580x20 cell array. To do this, I want to copy each element of the original 5580 elements twenty times. Does anyone happen to know of a simple way to do this? I have very little exerpience with matlab, so am not sure which functions would be best to approach this problem with. Thank you in advance for your help!!
What I currently have:
a = '1' '0' '1' '1' '0' ....etc
The cell array I want:
a =
'1' '1' '1' '1' etc... for 20 cells
'0' '0' '0' '0' etc... for 20 cells
'1' '1' '1' '1' etc... for 20 cells
'1' '1' '1' '1' etc... for 20 cells
...repeated for all original 5580 elements..

답변 (1개)

SAA
SAA 2020년 8월 19일
If you only have a logical character vector why do you want them all to be in a cell arrays and not just a matrix? But anyhow this should do what you want:
b = num2cell(str2num(a).*ones(size(a,1),20));
you can also not do num2cell and just work with a regular matrix which in my opininon is just easier to work with.

카테고리

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