Undefined function 'log' for input arguments of type 'table'.

7 ビュー (過去 30 日間)
Erik Öhrner
Erik Öhrner 2017 年 4 月 21 日
コメント済み: Erik Öhrner 2017 年 4 月 24 日
I'm trying to import Excel sheets into Matlab and then performing log function on them but always get "Undefined function 'log' for input arguments of type 'table'.". Its a fresh install of Matlab and I have just started working with the software.
So, I have two sheets which I just renamed to X and Price and then type the following: Ln_P=log(Price);
And I also tried with the other one Ln_X=log(X);
Still same errors.
  2 件のコメント
Adam
Adam 2017 年 4 月 21 日
Your data is in a table object. As the error says, the log function does not accept 'table' types. If your data is purely numeric then just load it into a regular array. Otherwise look at
and the section on 'Applying Functions to Table Contents'
Erik Öhrner
Erik Öhrner 2017 年 4 月 24 日
Yes, the problem was that I needed the Excel data to be in Numeric format and when I changed that it worked. Thanks for answering.

サインインしてコメントする。

回答 (3 件)

Eng. Fredius Magige
Eng. Fredius Magige 2017 年 4 月 21 日
Hi try: log10 it should work
  1 件のコメント
Erik Öhrner
Erik Öhrner 2017 年 4 月 21 日
Thanks for answering so quick, but same outcome however.

サインインしてコメントする。


Eng. Fredius Magige
Eng. Fredius Magige 2017 年 4 月 21 日
Hi Why not try: Ln_P=log10(Price);
Ln_X=log10(X);

Steven Lord
Steven Lord 2017 年 4 月 21 日
Tables can contain data of any type. Operate on just the variable(s) that contain numeric data. There are several ways to do this:
% Sample table
T = table(categorical({'M';'F';'M'}),[45;32;34],...
{'NY';'CA';'MA'},logical([1;0;0]),...
'VariableNames',{'Gender' 'Age' 'State' 'Vote'})
% Extract the variable by name
meanAge = mean(T.Age);
% Extract the variable by variable number
didAllVote = all(T{:, 4}) % the Vote variable
% Extract the variable by type
oldest = max(T{:, vartype('double')})
For more techniques you can use to work with data in a table, see the "Access Data in a Table" and "Calculations on Tables" section of the documentation for table.
Personally, where possibly I try to use the syntax involving the name of the variable -- that's independent of the order of the variables in the table and usually the most self-documenting option. When you see meanAge = mean(T.Age); in a block of code, you can understand the purpose of that code pretty quickly.

カテゴリ

Help Center および File ExchangeTime Series Collections についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by