Matrix dimensions must agree error

1 回表示 (過去 30 日間)
Akshat Shrivastava
Akshat Shrivastava 2018 年 8 月 7 日
t = sample.VarName1;
X = sample.VarName2;
indexOfComments = find(~isnan(sample.VarName3));
timeofcomment = sample.VarName1(indexOfComments);
t_end = t(indexOfComments);
indexTrim = t >= t_end - 5 & t <= t_end + 5 ;
t = t(indexTrim);
X = X(indexTrim);
Fs = 1/(t(2)-t(1));
I am getting an error 'Matrix dimensions must agree.'
Error in Untitled2 (line 106)
indexTrim = t >= t_end - 5 & t <= t_end + 5 ;
Please help!!
  2 件のコメント
Dennis
Dennis 2018 年 8 月 7 日
t and t_end might both be vectors of different sizes. Then you can't check if t>=t_end.
Akshat Shrivastava
Akshat Shrivastava 2018 年 8 月 7 日
Hello Dennis, t is the vector which stores one column from the text file (which represents time). t_end is the vector which stores 'index number' of the rows which has comment on the third column of the text file. can you tell me what should i do to make it work? Thank you.

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

採用された回答

Dennis
Dennis 2018 年 8 月 7 日
I hope i understood your code right, this might help:
t = sample.VarName1;
X = sample.VarName2;
indexOfComments = find(~isnan(sample.VarName3));
timeofcomment = sample.VarName1(indexOfComments);
t_end = t(indexOfComments);
r=zeros(numel(t_end)*11,1);
for i=1:numel(t_end)
r((i-1)*11+1:(i-1)*11+11)=t_end(i)-5:t_end(i)+5;
end
r=unique(r(r>0))
t=t(r(r<=numel(t)));
X = X(r(r<=numel(X)));
Fs = 1/(t(2)-t(1));
  1 件のコメント
Akshat Shrivastava
Akshat Shrivastava 2018 年 8 月 7 日
Thanks for the help !!

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!