Why do I receive this error when using cumsum: "Invalid data type. First input argument must be numeric or logical." ?
Show older comments
Hi,
I am a psychologist with very little experience in Matlab and am just trying to run a code (see attachment). The function is:
function [H]=dfaedit(file_name,plot_flag, outfile_flag, out_command_flag)
When calling the fucntion with the input arguments I always receive the error:
Error using cumsum
Invalid data type. First input argument must be numeric or logical.
Error in dfaedit (line 44)
Sum = cumsum(x);
I have tried using different file types (.txt, .dat, .csv), different imported variables (matrix, table, vectors, etc.) and extracting data from vectors but no matter the input I get the same cumsum error. The data itself is just a single column of integer values.
At first I thought that my data wasn't numerical but after having tried out all of the steps mentioned above I am out of ideas. Could anyone help me out?
Sorry if this seems obvious :)
Thanks!
4 Comments
Torsten
on 8 Jan 2022
Could you also include your calling program and the Textfile ?
lil brain
on 8 Jan 2022
Torsten
on 8 Jan 2022
No, I mean what you wrote to fill the ... below:
function call
file_name = ...;
plot_flag = ...;
outfile_flag = ...;
out_command_flag = ...;
H = dfaedit(file_name,plot_flag,outfile_flag,out_command_flag)
end
lil brain
on 8 Jan 2022
Accepted Answer
More Answers (1)
The code (that appears to have been written in 2001) doesn’t make sense!
The first argument to the function is ‘file_name’ that I assume would be a character array. It is subsequently assigned to ‘x’ and then the ‘Sum’ variable is assigned as cumsum(x). Doing any sort of calculation on a character array (without first converting to a numeric representation of the elements of the character array) isn’t possible.
That is throwing the error.
Please go back and review the documentation to determine what the arguments are supposed to be.
opts = weboptions('ContentType','text');
W = webread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/857175/dfaedit.m', opts)
.
Categories
Find more on JSON Format 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!