Data conversion: Data type cell to char within a cell array
5 views (last 30 days)
Show older comments
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 Comments
dpb
on 4 Dec 2020
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
on 4 Dec 2020
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');
Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!