Question
I am trying to store a MATLAB duration object inside a cell array using cellstr() or direct assignment, but MATLAB throws Error: Cannot convert data of class 'duration' into cell array. How do I properly convert duration arrays to strings or cell arrays?
Expert Answer
Neeta Dsouza
PhD Expert
Answered Aug 24, 2026
To convert a MATLAB duration array into a cell array of strings, convert the duration object to a string array first before wrapping it into a cell array, rather than passing the duration object directly into cellstr().
Solution Code:
% Create duration array [01:00:00, 02:00:00, 03:00:00]
d = hours(1:3);
% Convert duration to string array first, then to cell array
cellArray = cellstr(string(d));
disp(cellArray);
Alternatively, if you want a custom formatted string representation:
d.Format = 'hh:mm:ss';
cellArray = cellstr(char(d));
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related MATLAB Data Types Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →