필터 지우기
필터 지우기

Convert char fields of structure into a cell array

조회 수: 13 (최근 30일)
Stefanie
Stefanie 2014년 2월 21일
댓글: as a 2021년 4월 22일
I have a structure with fields like
A(1).a='A01'
A(2).a='A02'
A(3).a='A03'
Now I would like to convert this structure into a cell array. I tried with
B=[A.a]
B =
A01A02A03
That is not, what I need. I would like to have:
B =
'A01'
'A02'
'A03'
Is there an easy way, or do I need to write a loop for that?

채택된 답변

Sean de Wolski
Sean de Wolski 2014년 2월 21일
편집: Sean de Wolski 2014년 2월 21일
You could also use comma-separted list expansion:
ac = {A(:).a}
Similar to what you did above, but rather than concatenating the strings with [], concatenate them into cells with {}.
  댓글 수: 5
Marie-Claude Boisvert
Marie-Claude Boisvert 2017년 9월 7일
편집: Marie-Claude Boisvert 2017년 9월 7일
Hi, I tried it and got a new string vector :) super , but do you know how to change it directly in the Structure (A here) ? Thanks
as a
as a 2021년 4월 22일
I think what u need is B = char(A.a)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by