how to solve this error horzcat Dimensions of matrices being concatenated are not consistent?

10 ビュー (過去 30 日間)
Hi all, how can i solve this error:
t=Tp';
dt =t(2)-t(1);
vdrift = filter(d,drift)/dt;
delay=mean(grpdelay(d))
tt = t(1:end-delay);
vd = vdrift;
vd(1:delay) = [];
tt(1:delay) = [];
vd(1:delay) = [];
[pkp,lcp] = findpeaks(drift);
zcp = zeros(size(lcp));
[pkm,lcm] = findpeaks(-drift);
zcm = zeros(size(lcm));
figure,plot(t,drift,t([lcp lcm]),[pkp -pkm],'-',"LineWidth",2)
Error
Values of matrix are:
  1 件のコメント
Paul Hoffrichter
Paul Hoffrichter 2021 年 3 月 7 日
Multiple problems.
[lcp lcm] % this expression gives the error you are reporting
[pkp -pkm] % same error
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
And since the arrays are wrong, it is not clear what your intent is. Did you want to stack lcp over lcm, like this:
a = [lcp; lcm];
length(a)
ans =
1859
Moving on, the following at least corrects the error message:
plot(t,drift, t([lcp; lcm]),[pkp; -pkm], '-', "LineWidth", 2);

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

採用された回答

Mario Malic
Mario Malic 2021 年 3 月 7 日
Hi Miguel,
When you type [var1 var2], you are concatenating horizontally, since your variables have different number of rows, you'll get an error.
This seems troublesome, I don't really understand what are you trying to do here, can you explain?
t([lcp lcm]),[pkp -pkm]
  5 件のコメント
Mario Malic
Mario Malic 2021 年 3 月 7 日
Take a look at findpeaks and max in documentation. First one requires Signal Processing Toolbox.
Miguel Minga
Miguel Minga 2021 年 3 月 7 日
Thanks Mario
I tried it with this code and it works
figure
plot(t(lcp), pkp,'-', 'LineWidth',2)
legend('Max peak value')
xlabel('Time [s]')
ylabel('Displacement [mamsl]')

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDigital Filtering についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by