How to change precision using cellfun and num2str

2 Ansichten (letzte 30 Tage)
Brooke Sarley
Brooke Sarley am 19 Feb. 2016
Beantwortet: Walter Roberson am 19 Feb. 2016
I'm trying to convert a column of data into a column of strings. I've used the cellfun function:
data_compiled=compiled_data_import('data compiled.csv');
timestamps=cellfun(@num2str,data_compiled(:,1),'UniformOutput', false);
And that works but the output is rounding off too soon. I know you can specify precision when using num2str but I don't know what to put in for the first argument of num2str since I call the numbers to convert in the cellfun function.
Would it be something like:
data_compiled=compiled_data_import('data compiled.csv');
timestamps=cellfun((x)@num2str(x,3),data_compiled(:,1),'UniformOutput', false);
? Please help.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 19 Feb. 2016
Very close.
timestamps=cellfun(@(x) num2str(x,3),data_compiled(:,1),'UniformOutput', false);

Weitere Antworten (0)

Kategorien

Mehr zu Structures 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!

Translated by