using for loop in alignsignal function

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 Kommentar

Debanjan Borthakur
Debanjan Borthakur am 10 Jun. 2019
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

Melden Sie sich an, um zu kommentieren.

Antworten (2)

KALYAN ACHARJYA
KALYAN ACHARJYA am 10 Jun. 2019
Bearbeitet: KALYAN ACHARJYA am 10 Jun. 2019

0 Stimmen

%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 Kommentare

Debanjan Borthakur
Debanjan Borthakur am 10 Jun. 2019
Bearbeitet: Debanjan Borthakur am 10 Jun. 2019
Thanks ACHARJYA, but my Y is a vector and X is a matrix ( say X1,X2,X3). Now I want to alignsignals Y and X1, Y and X2 and so on ...
Debanjan Borthakur
Debanjan Borthakur am 10 Jun. 2019
I always get this error : Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Debanjan Borthakur
Debanjan Borthakur am 10 Jun. 2019
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
KALYAN ACHARJYA
KALYAN ACHARJYA am 10 Jun. 2019
Bearbeitet: KALYAN ACHARJYA am 10 Jun. 2019
@Debanjan data?
Debanjan Borthakur
Debanjan Borthakur am 10 Jun. 2019
data is just a matrix (2961*258)

Melden Sie sich an, um zu kommentieren.

KSSV
KSSV am 10 Jun. 2019

0 Stimmen

[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 Kommentare

Debanjan Borthakur
Debanjan Borthakur am 10 Jun. 2019
hi, your first line results error : Too many output arguments.
Debanjan Borthakur
Debanjan Borthakur am 10 Jun. 2019
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 Borthakur
Debanjan Borthakur am 10 Jun. 2019
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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by