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 件のコメント

Debanjan Borthakur
Debanjan Borthakur 2019 年 6 月 10 日
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

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

回答 (2 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 10 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 10 日

0 投票

%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 件のコメント

Debanjan Borthakur
Debanjan Borthakur 2019 年 6 月 10 日
編集済み: Debanjan Borthakur 2019 年 6 月 10 日
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 2019 年 6 月 10 日
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 2019 年 6 月 10 日
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 2019 年 6 月 10 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 10 日
@Debanjan data?
Debanjan Borthakur
Debanjan Borthakur 2019 年 6 月 10 日
data is just a matrix (2961*258)

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

KSSV
KSSV 2019 年 6 月 10 日

0 投票

[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 件のコメント

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

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

カテゴリ

質問済み:

2019 年 6 月 10 日

コメント済み:

2019 年 6 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by