How can I fix a "Subscripted assignment dimension mismatch."

1 view (last 30 days)
hi, my project is about atrial fibrillation I want to use butterworth method to filter out the signal, however when i use filtfilt it keep saying "Subscripted assignment dimension mismatch" which didnt occur in the first few runs
Can someone please help me
Thanks
%%Signals with no fitler
Virtuals = loadmat('LA_D_001_PRE_subtracted_VIR.mat');
Virtuals = Virtuals';
subplot(3,1,1);
plot(Virtuals);
title('Signals with no filter');
xlabel('Time');
%%Applying with Butterworth filters
X = Virtuals;
%First order
[b, a]= butter(1, [4/256 10/256]);
%%Filtfilt
for i=1:2048
Y2(i,:)=filtfilt(b,a,X(i,:));
end
subplot(3,1,2);
gplot(Y2,b);
hold on;
gplot(Y2,a);
hold off;
title('signals with Butterworth filter - First order');
xlabel('Time');
%%phase
A= Y2';
% waitbar(6/8)
% [r c]=size(A);
% Phase=zeros(size(A));
for j=1:size(A,1)
s=squeeze(A(j,:));
s=s-mean(s);
ha=imag(hilbert(s));
Phase(j,:)=-atan2(ha,s);
end
clear A
  4 Comments
Star Strider
Star Strider on 26 Jan 2015
Is ‘Virtuals’ a cell array? What size it is? At what value of ‘i’ does the error occur?
(It is not advisable to use i or j as variables. MATLAB uses them as its imaginary operators, so using them as variables could cause confusion.)
tram nguyen
tram nguyen on 26 Jan 2015
Edited: tram nguyen on 26 Jan 2015
geoff, i've tried to used debugger but it says error and cannot be used
ive tried cell array but it didnt seem to work
it is a very large size, 2048x148765
the file is too big that i cannot upload it here :(

Sign in to comment.

Answers (1)

dpb
dpb on 26 Jan 2015
Edited: dpb on 26 Jan 2015
First, eliminate all the spurious code that has no bearing on the problem...the plotting and such is of no use; is simply distraction.
Second, paste the actual error message in context from the window with the offending line; don't make us guess which of the possible lines it actually is that is the offender.
Third, it appears given the code that the likely culprit is that you change the definition of the input data from one case to a previous and didn't redefine or clear Y2 between those and so the failing length of the array isn't the same as that of the first.
Insert a
clear Y2
before the loop and see if that doesn't fix the problem.
It would be better if you were to preallocate Y2 rather than dynamically resizing it each pass...
There are at least a couple of other anomalies/possible problems here--
1) What's the magic number 2048; where did it come from?
2) You plotted(*) the unfiltered signals by column since you transposed the input array but you're processing them/applying the filter by row, not column. That doesn't make any sense.
%%Applying with Butterworth filters
[b, a]= butter(1, [4 10]/256);
Virtuals = loadmat('LA_D_001_PRE_subtracted_VIR.mat').';
Y2=zeroes(size(Virtuals)); % allocate output same size for filtered
for i=1:size(Virtuals,2) % filter each column
Y2(:,i)=filtfilt(b,a,Virtuals(:,i));
end
(*) So, I guess in that context the *plot* _does_ add something in that it seems to demonstrate the orientation of the data in the array. Of course, if it is actually the other way 'round then the plot is wrong and the filtered signal could be right. We can't know that; only you know for sure which way the data are stored in the file (or at least hopefully you do or they're such that it's easy to verify which is which). But, the key is we can't tell from here...

Products

Community Treasure Hunt

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

Start Hunting!