필터 지우기
필터 지우기

how to convert cell to char ?

조회 수: 5 (최근 30일)
Leonardo Wayne
Leonardo Wayne 2016년 4월 1일
답변: Image Analyst 2016년 4월 1일
I have the following cell array called raw. I want to convert the contents of the column 19 into a character array in a and put it in a variable as such :
str = '160225MD0004;#2;#13161504900013;#1';
The str will have only that value. I don't want the first cell 'Part number Details'.
I don't want the extra empty cells [].
Most importantly, I want to automatically detect wherever the '160225MD0004;#2;#13161504900013;#1' is. For now it is in the 6th field. But it could change to 7th field for example.
And the '160225MD0004;#2;#13161504900013;#1' could change into '123345KR00994;#3;#160225MD0004;#2;#13161504900013;#1'; In other words, it could have any length.
How can this be done?

채택된 답변

KSSV
KSSV 2016년 4월 1일
You can remove all empty cells from a cell array using R(~cellfun('isempty',R)). Eg:
R = cell(10,1) ;
R{2} = rand(3) ;
R{6} = rand(3) ;
l = R(~cellfun('isempty',R)) ;

추가 답변 (1개)

Image Analyst
Image Analyst 2016년 4월 1일
Try this:
% Create sample data:
ca = {'160225MD0004;#2;#13161504900013;#1;', [], 123, [], '123345KR00994;#3;#160225MD0004;#2;#13161504900013;#1'}
% Get only the part numbers that are strings:
partNumbers = ca(~cellfun(@isnumeric, ca))

카테고리

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