Hello,
I have a char array with the dimensions of 100x4 and because it contains blank elements, in other words 4 charactered space ' ', I want to merge these elements and delete these 4 charactered blank elements. How can I do it? Thank you.

댓글 수: 2

Rik
Rik 2022년 6월 7일
If you want to remove elements, this will change the number of elements, so any column vector will not have 400 elements.
It sounds like you should be using a cellstr (a cell array with char vectors) or the string data type.
tinkyminky93
tinkyminky93 2022년 6월 7일
편집: tinkyminky93 2022년 6월 7일
That is what I want sir, i will remove them because it does not contains any information.

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

 채택된 답변

KSSV
KSSV 2022년 6월 7일
You have varities of functions to achieve this.
Try:
str = str(find(~isspace(str))) ; % where str is your string

댓글 수: 5

tinkyminky93
tinkyminky93 2022년 6월 7일
편집: tinkyminky93 2022년 6월 7일
Now it shows
{0x0 double} {0x0 double}
{0x0 double} {0x0 double}
{'00'} {'00'}
any methods to remove 0x0 doubles? I need hex 00 00 values but not empty 0 elements :)
Once you have a cell array it's relatively easy to remove the empty elements:
str={[],[],[],[],'00','00'}
str = 1×6 cell array
{0×0 double} {0×0 double} {0×0 double} {0×0 double} {'00'} {'00'}
str(cellfun('isempty',str))=[]
str = 1×2 cell array
{'00'} {'00'}
Great! You can write it to answer section so that I can accept your answer. Now I have 32x1 cell which have 2x1 elements in every row. How can I merge them like 1x1? For example
0E
F9
to
'0EF9'
I don't understand your source data. With a 2x6 char array as an input, you don't get the cell array output with the code KSSV posted. So I can't post the full processing.
Regarding the merging:
str={'0E';'F9'}
str = 2×1 cell array
{'0E'} {'F9'}
[str{:}]
ans = '0EF9'
@tinkyminky93 why don't you attch your data, so that we can have a look and help you.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 6월 7일

댓글:

2022년 6월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by