need to find local maxima and minima of each row of a 7886 * 321 matrix stored in xlsx file.

1 回表示 (過去 30 日間)
filename = 'filtereddata.xlsx';
data = xlsread(filename);
Diff1= diff(data,1,2);
[rows, columns] = size(data);
extrema = zeros(7886,321);
for i=1:rows
[Diff1max,imax1,Diff1min,imin1] = extrema(Diff1(i,:));
end
Error: Insufficient number of outputs from right hand side of equal sign to satisfy assignment.

採用された回答

Voss
Voss 2022 年 5 月 1 日
extrema is a 7886-by-321 matrix of zeros, so this expression:
extrema(Diff1(i,:))
says to get the elements of extrema at the indices given by Diff1(i,:). Those elements will be in a single matrix, so trying to assign them to the four variables Diff1max,imax1,Diff1min,imin1 is what causes the error.
I suspect you intend to use the function extrema from the File Exchange (https://www.mathworks.com/matlabcentral/fileexchange/12275-extrema-m-extrema2-m), in which case you should avoid naming a variable the same name as that function. Use another name for the variable extrema, say my_extrema, if you need that variable (which it's not clear whether you do).
my_extrema = zeros(7886,321); % variable
for i=1:rows
[Diff1max,imax1,Diff1min,imin1] = extrema(Diff1(i,:)); % function call
% do something with the outputs from extrema function
% Diff1max,imax1,Diff1min,imin1
end
  6 件のコメント
NotA_Programmer
NotA_Programmer 2022 年 5 月 1 日
"One way to handle such a situation is to use cell arrays:"
- Yes, this worked.
Thanks a lot!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by