Data conversion: Data type cell to char within a cell array

조회 수: 5 (최근 30일)
Tim
Tim 2020년 12월 4일
댓글: Image Analyst 2020년 12월 4일
I have 15 cell arrays, size 1000+ x 5 and two of the columns need to be converted from data type cell to char.
This for loop works without any issues.
for i = 1: length(cell_array1)
x = char(cell_array1{i,1});
y = char(cell_array1{i,3});
cell_array1{i,1} = x;
cell_array1{i,3} = y;
end
However, when I adjust the for loop to loop through 15 different cell arrays, it returns data type cell in both columns I need to change to char.
a = {cell_array1, cell_array2};
for j = 1: length(a)
for i = 1: length(a{j})
x = char(a{i,1});
y = char(a{i,3});
a{j}{i,1} = x;
a{j}{i,3} = y;
end
end
  댓글 수: 6
dpb
dpb 2020년 12월 4일
That's the problem with having built separate variables..."there be dragons!"
If you have separate variables to operate on, then you have to write code to address those variables. There's no point in putting them in e if you're not going to use it instead; just operate on c, d individually. Of course, when you do, then you'll probably have to continue to duplicate going forward to do the same thing on both.
As said, I think it's time to revisit the beginning of how you got yourself into the mess and extricate yourself therefrom back there rather than following this path.
Image Analyst
Image Analyst 2020년 12월 4일
Attach your cell arrays in a .mat file if you have any more problems (so we can quite guessing).
save('answers.mat', 'cell_array1', 'cell_array2');

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by