Error using findpeaks Expected Y to be one of these types: double, single Instead its type was table.

31 ビュー (過去 30 日間)
Hi,
I am trying to read a file and find its peak. But the findpeak function keeps throwing errors. Please help. I am new to matlab.
%clear,clc
readtable('KD.xlsx');
x=qw(:,1);
y=qw(:,2);
%y=data(:,2');
Peaks=findpeaks(ans);
[pks,locs] = findpeaks(KD);
plot(x,y,y(locs),pks,'or')
xlabel('Xvalue')
ylabel('Peak')
axis tight
error message:
Error using findpeaks
Expected Y to be one of these types:
double, single
Instead its type was table.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in Untitled (line 6)
Peaks=findpeaks(ans);
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 1 月 16 日
You have a clear at the top of your code. Where are you expecting the array qw to be pulled out of?
Peaks=findpeaks(ans);
I recommend against relying on the value of ans in programming. Someone (you, later in time) should not have to know that inserting additional statements that do not modify existing variables could end up changing the meaning of the code because they happen to change ans.
Venkatakrishnan Rengarajan
Venkatakrishnan Rengarajan 2021 年 1 月 16 日
My bad. I have my array imported in the name qw.

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

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 1 月 16 日
Best to use variable you define rather than ans.
The function readtable returns a table. Each column of a table is, in turn, a variable. So a table is made up of variables.
The input for findpeaks must be a variable, but you are passing in the entire table. The error will be fixed if you can instead pass in a variable.
See this page for how to access data in a table. Any of the syntaxes that return an array are what you need. If you know the variable name, the simplest is to use dot notation.
Peaks=findpeaks(Tname.Varname);
  7 件のコメント
Walter Roberson
Walter Roberson 2021 年 1 月 16 日
What shows up for
which -all findpeaks
Venkatakrishnan Rengarajan
Venkatakrishnan Rengarajan 2021 年 1 月 17 日
編集済み: Venkatakrishnan Rengarajan 2021 年 1 月 17 日
I just realized that, before starting this problem, I downloaded a set of functions from a university website. It had findpeaks command in it. The input in that command was different compared to the default "findpeak" command in the signal processing toolbox. After I deleted the my downloaded package (i just changed the file path, tbh), it worked perfectly.
Thanks for all the comments and help. I really appreciate it.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by