Can't calculate mean of dataset (single column), "[F]irst argument must be numeric or logical"

1 view (last 30 days)
I am currently trying to determine the mean, median, and mode of a given dataset.
Right now, the data is in what I believe to be a string. There should be no text in said strings, only numeric data.
The dataset in question is a "string" that has only one column full of data.
I wish to, as a start, determine the mean.
When I attempt to do so, I get this error.
M = mean(Dataset)
Error using sum
Invalid data type. First argument must be numeric or logical.
Error in mean (line 127)
y = sum(x, dim, flag) ./ mysize(x,dim);
I checked using
tf = istable
That the dataset was not a table.
May someone provide guidance as to what I am doing wrong? If I need to convert the dataset, how and to what?
Walter Roberson
Walter Roberson on 22 Sep 2022
Your reasoning does not make sense. You would not be able to take the string array and "properly plot of subplot via histfit in table format" with the string array.
You should either readmatrix() or readtable(), and if you use readtable() then use variable-name or column references as appropriate when calling functions.

Sign in to comment.

Answers (1)

Pravarthana P
Pravarthana P on 26 Sep 2022
Hi Austin Davis,
I understand that you are facing an issue while calculating the mean of a given dataset in ‘string’ datatype.
In order to use the ‘mean’ function the input should be in any one of the mentioned data types in this documentation link.The dataset can be converted to the required data type using "str2double" function, following which,- the mean can be calculated.
For further information kindly refer to the following documentation links:
I hope this information helps you!


Find more on Characters and Strings 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!

Translated by