How do I convert double to cellstr?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Dominic Noel Kluck
am 22 Jan. 2024
Beantwortet: Sai Teja G
am 22 Jan. 2024
I have a vector which coul look like this: A = [2 25 1017]. I want to use these numbers in a legend of my plot. Apparently I need to convert them from double into cellstr. Thats what I get out of the error message: Cell array argument must be a cell array of character vectors. How do I convert double into cellstr?
Thanks in advance
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Sai Teja G
am 22 Jan. 2024
Hi Dominic, You can refer to the below code to convert double to cell array.
A = [2 25 1017];
A_str = arrayfun(@(x) num2str(x), A, 'UniformOutput', false)
This code snippet uses arrayfun to apply the num2str function to each element of the array A, converting each number to a string. The 'UniformOutput', false argument is used to output the results in a cell array, which is necessary for the legend function in MATLAB.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!