필터 지우기
필터 지우기

Cell array to Matrices

조회 수: 2 (최근 30일)
fartash2020
fartash2020 2018년 6월 21일
댓글: fartash2020 2018년 6월 21일
Dear Matlab users, I have a cell array B 1x512 . now I want to divide every cell to a new matrix. So I will have 512 matrices.I prefer their names to be C1,C2...,C512. every "C" matrix is 10001x3 matrix.
I am using cell2mat option, but I want to write a loop which I cannot do it
C1=cell2mat(B(1))
thi is working just for one, I do not want to do it one-by-one.
Thanks in advance,

채택된 답변

Guillaume
Guillaume 2018년 6월 21일
You already have your C1, C2, ..., C512 in a very convenient container making it very easy to access: your cell array. Assuming your cell array is called C and not B, to get C1:
C{1}
to get C2:
C{2}
etc.
Creating numbered variables is an extremely bad idea. It's just going to make your code more complicated, slower, harder to debug for no gain whatsoever. See tutorial-why-variables-should-not-be-named-dynamically-eval for a complete explanation
What it looks like from your cell2mat(B(1)) is that you don't know how to access the data in a cell array. See the tutorials on the cell array page to learn the difference between () and {} indexing.
  댓글 수: 1
fartash2020
fartash2020 2018년 6월 21일
Tnx Guillaume, you are right. I do not need to convert anything.
With my best regards,

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

추가 답변 (1개)

KL
KL 2018년 6월 21일
Use 3D matrices, it's a better idea.
C_mat = cell2mat(permute(C,[1,3,2]))
  댓글 수: 2
fartash2020
fartash2020 2018년 6월 21일
To simply state what I want:
C1=cell2mat(B(1))
C2=cell2mat(B(2))
.
.
.
C512=cell2mat(B(512))
I want to write a loop for this
Walter Roberson
Walter Roberson 2018년 6월 21일
We firmly recommend against that. It would be better to continue to index the cell array.
If you have the case of needing to create each of the entries as separate variables in a .mat file then we can do that without ever creating the variables in your workspace.

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

카테고리

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

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by