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

3 visualizaciones (últimos 30 días)
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?
Thanks.
  6 comentarios
dpb
dpb el 22 de Sept. de 2022
Editada: dpb el 22 de Sept. de 2022
There should be no need for any such machinations with strings...if you imported as a MATLAB table, then the problem probably had to do with not using the variables within the table but trying to reference the table itself.
Again, attach a piece of the Excel file itself and tell us what you're trying to do -- we can't see your terminal from here and can't debug what we can't see...it is possible that sometimes a spreadsheet file can be save such as it does lead to confusion as to data types -- not terribly often, but can/does happen. Or, there are other fields in the file that don't match up -- all kinds of superfluous stuff is occasionally stuffed into a spreadsheet for auxiliary data or explanation or whatever.
Walter Roberson
Walter Roberson el 22 de Sept. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Pravarthana P
Pravarthana P el 26 de Sept. de 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!

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by