MATLAB Answers

0

using for loop in alignsignal function

Asked by Debanjan Borthakur on 10 Jun 2019
Latest activity Commented on by Debanjan Borthakur on 10 Jun 2019
I am using the function [Xa,Ya] = alignsignals(X,Y). Now I want to perform this operation on an arry of X and Y's and store them on Xa's and Ya's. Any suggestions. Here X and Y will be a matrix instead of a single vector.

  1 Comment

Here is my code which does not work :
d1=resample(data,25,200); %% here d1 is my matrix and I want to align signal1 with each of the columns of d1.
for i=1:size(d1,2)
%[Xa(i),Ya(i)]=alignsignals(X(i),Y(i));
[xx(i),yy(i)]=alignsignals(signal1(i) ,d1(:,i));
end

Sign in to comment.

2 Answers

Answer by KALYAN ACHARJYA on 10 Jun 2019
Edited by KALYAN ACHARJYA on 10 Jun 2019

%I assumed both (X & Y) have same lengths
for i=1:lengths(x)
[Xa(i),Ya(i)]=alignsignals(X(i),Y(i));
end
For example
y1=[1 2 3 4];
y2=[4 5 6 7];
x=[];
y=[];
for i=1:length(y1)
[x(i) y(i)]=fun4(y1(i),y2(i));
end
fun4
function [x y]=fun4(a,b)
x=a+b;
y=a-b;
end
If I misundestood your question, let me know.

  5 Comments

Here is my code which does not work :
d1=resample(data,25,200); %% here d1 is my matrix and I want to align signal1 with each of the columns of d1.
for i=1:size(d1,2)
%[Xa(i),Ya(i)]=alignsignals(X(i),Y(i));
[xx(i),yy(i)]=alignsignals(signal1(i) ,d1(:,i));
end
@Debanjan data?
data is just a matrix (2961*258)

Sign in to comment.


Answer by KSSV
on 10 Jun 2019

[m,n] = size(X) ;
Xa = zeros([],m) ;
Ya = zeros([],n) ;
for i = 1:n
[xa,ya] = alignsignals(X(:,i),Y(:,i)) ;
Xa(:,i) = xa ;
Ya(:,i) = ya ;
end
If function is shown...may be it can be vectorised and work for entire matrix.

  3 Comments

hi, your first line results error : Too many output arguments.
Here is my code which does not work :
d1=resample(data,25,200); %% here d1 is my matrix and I want to align signal1 with each of the columns of d1.
for i=1:size(d1,2)
%[Xa(i),Ya(i)]=alignsignals(X(i),Y(i));
[xx(i),yy(i)]=alignsignals(signal1(i) ,d1(:,i));
end
d1=matrix (2961*258)
n=258
m=n
Xa = zeros([],m) ;
Ya = zeros([],n) ;
for i = 1:n
[Xa(1:length(M_1norm),i),Ya(:,i)] = alignsignals(M_1norm,d1(1:length(M_1norm),i)) ;
end
Unable to perform assignment because the size of the left side is 0-by-1 and the size of the right side is 3292-by-1.

Sign in to comment.