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

5 次查看(过去 30 天)
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