Here I have a cell 52*3 cell. I want to split this into 3 cells; each of 52*1 size .
I want this to be done in any automated way like using by any loop or any other way
How can I split this?

답변 (1개)

Image Analyst
Image Analyst 2021년 7월 4일

0 개 추천

If ca is your 52x3 cell array, you can make 3 cell arrays by taking each column and putting it into its own cell array
col1 = ca(:, 1);
col2 = ca(:, 2);
col3 = ca(:, 3);
Each of those is a 52 x 1 cell array.
Please refer to the FAQ.
I think it will help you a lot.

댓글 수: 4

Durlov Rahman
Durlov Rahman 2021년 7월 4일
편집: Durlov Rahman 2021년 7월 4일
@Image Analyst Yeah I know this way. But I want this to be done in any automated way like using by any loop or any other way
Image Analyst
Image Analyst 2021년 7월 4일
편집: Image Analyst 2021년 7월 4일
@Durlov Rahman, this is the simplest, most straightforward way, and the most compact (if that matters).
Not sure of your definition of automated, but this is as automated as any other way. No manual/interactive user assistance is required.
Surely you don't mean to do the terrible operation advised strongly against in the FAQ, do you?
Maybe you should just avoid creating the data in that 52x3 cell array form to begin with. If all the cells contain the same size array, it's best to use a regular double array. Cell arrays are horribly inefficient and wasteful of memory.
Durlov Rahman
Durlov Rahman 2021년 7월 4일
편집: Durlov Rahman 2021년 7월 4일
yeah brother you are right. But I was thinking that if there is 52*4 cell, then 4 cells of 52*1 size will be automatically generated. if 52*5 then 5 cells of 52*1 size will be automatically generated. I want a way in which I need not declare col1 col2 col3 col4 etc.every time. This variable will be automatically created
Image Analyst
Image Analyst 2021년 7월 4일
Who made this cell array? Was it you? Or were you given it by someone else so you are stuck with it? Frankly, I don't see anything wrong with leaving it in an array. If you need to extract one column or the contents of one cell, you can do that just one-by-one as you need it inside whatever loop you're running.

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2021년 7월 4일

댓글:

2021년 7월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by