What does 'Undefined operator '*' for input arguments of type 'table'' mean?

I have defined all the values to the following equation
ViNew(t,k) = (alpha)*(ViOld)*(t - 1)+(1 - alpha)*Qi(t)
and have asked Matlab to solve it as part of a function for loop. I have defined k as 1:length(1:80), which is the length of the excel sheet where I want my answers placed. Every part of the function is running except for the equation. It says that there is an
Undefined operator '*' for input arguments of type 'table''
I have no idea what that means and how I can fix it. Any guesses?

1 Comment

It means you are trying to multiply a table object by something and table object does not have a '*' multiplication operator defined. Can't really say more than that as you haven't shown any code. I don't use tables, but usually you would have to use some method to operate on each value of a column or row of a table rather than trying to just multiply the table object itself.

Sign in to comment.

Answers (1)

I suspect you are using readtable() to read a .xls or .xlsx file, thinking that it will return a numeric vector . It will not do so: readtable() returns object-oriented objects of type "table". You cannot multiply a "table" by something.
If this is what is happening, you can either use xlsread() to read into numeric array, or you can use the table indexing operators to extract numeric values from the table; see http://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-table.html

2 Comments

function LinearOperator(data,alpha)
S=data
t=1 % At trial 1 individuals will have no experience for which reason ViOld=0
for t=S(:,1) %The data will provide trial # and corresponding Qi and ViOld
ViOld=S(:,2) %ViOld will be the reward collected at t-1 that will be integrated into an updating value for ViNew
end
for Qi=S(:,3) %Qi will be the reward collected at time t
end
k=1:length(1:80)%length is the same as the length of t
ViNew(t,k) = (alpha)*(ViOld)*(t - 1)+(1 - alpha)*Qi(t)
ViOld=ViNew
t=t+1
xlswrite('Social_tracking_data.xlsx','Vi',2)
end
This is my code.

Sign in to comment.

Categories

Asked:

on 13 Mar 2016

Commented:

on 13 Mar 2016

Community Treasure Hunt

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

Start Hunting!