Concatinating signals on Matlab

In summary, the user has different types of signals (impulse, Ramp, sinusoidal, Dc, exponential), and the user can have multiple selection. The user tells me how many time he want to select signals, but does not know how to concatenate the signal. MATLAB would see that as an assignment of form A(I)=B, and the user is getting an error message because he has not defined k.
  • #1
princess Maro
2
0
Hiiiiii Everyone ,

It is My First Post ...And I will be Very pleased if You helped me find a solution to my problem .

well... It is a Matlab code &

I have different type of signals (impulse ,Ramp, sinusoidal,Dc ,exponintial )

& the type of signal is determined by the user ( the user enter a number from 1 to 5) to determine the signal & the user can have multiple selection ..& the user tells me how many time he want to select signals

But The Problem i don't Know how to concatenate the signal .. I tried to make it like this
A=[];
for i=1:c+1
A=[A y(choice)]
end
but an error keeps bothering me
? In an assignment A(I) = B, the number of elements in B and
I must be the same.

please anyone help me..
 
Physics news on Phys.org
  • #2
So if you are storing the possible signals in vectors m1 m2 etc, and the user constructed vector is a, then, at each selection, you are doing a=[a,m1] (if type 1 was selected).
I think your error means that you have made a mistake in your assignments to do with the vector size. Check that you are concatenating to the right place with the correct orientation.

But I suspect it is the y(choice) part ... MATLAB would see that as an assignment of form A(I)=B you see?

i.e.
Code:
7> m=magic(4)
m =

   16    2    3   13
    5   11   10    8
    9    7    6   12
    4   14   15    1

8> a=m(1,:)
a =

   16    2    3   13

9> a=[a,m(4,:)]
a =

   16    2    3   13    4   14   15    1

10> a=[a,m(:,3)]
error: number of rows must match (4 != 1) near line 10, column 6

10> a=[a;m(3,:)]
error: number of columns must match (4 != 8)

To be able to tell what is going wrong for you I need to see the code and the context for the error (the actual error message copy-and-past).
 
  • #3
Thanks Monsieur simone For Your Help :)

But That wasnot the point that i was asking about .. You R Right you have to see the code to be able to see the problem

c=input('enter the number of break point: ');

for n=1:c
m(1,k)=input('enter positions of break point:');
k=k+1;
end
p=[-5 m 3]; % The signal start at -5 & end at 3 & m is the position of the break

for k = 1:c+1
t=linspace(p(1,k),p(1,k+1),(p(1,k+1)-p(1,k))*100); % the frequency =100
choice=menu('Choose a type','y(1)','y(2)','y(3)','y(4)','y(5)');
if choice==1
g=p(1,k+1)-p(1,k);
y(1)=[4 zeros(1,(g-1))];
end
if choice==2
y(2)=5*ones(1,t);
end
if choice==3
y(3)=3*t+1;
end
if choice==4
y(4)=3*exp(-2);
end
if choice==5
y(5)=5*sin(100*t+30);
end

% Here i want to conatenate all the choosen signals & Plot it With T
% But i can't Write the proper code of concatination

T=linspace(-5,3,(3+5)*100);
A=ones(1,(3+5)*100);


end
 
  • #4
princess Maro said:
Thanks Monsieur simone[*] For Your Help :)

But That wasnot the point that i was asking about .. You R Right you have to see the code to be able to see the problem
I can see a number of problems with the below:

c=input('enter the number of break point: ');

for n=1:c
m(1,k)=input('enter positions of break point:');
k=k+1;
end
... you have not defined k - change the n to a k or the k to an n.

With this change, the output looks like this:
Code:
48> sig
enter the number of break point: 3
enter positions of break point:0.1
enter positions of break point:0.2
enter positions of break point:2
Choose a type

  [ 1] y(1)
  [ 2] y(2)
  [ 3] y(3)
  [ 4] y(4)
  [ 5] y(5)

pick a number, any number: 1
error: A(I) = X: X must have the same size as I
error: called from:
error:   /home/simon/sig.m at line 15, column 5

line 15 is:
if choice==1
g=p(1,k+1)-p(1,k);
y(1)=[4 zeros(1,(g-1))];
end

consider: what does "y(1)" mean to matlab?

- what do you y to look like?
if you want y to be a row vector containing the signal, then you can build it as you go.
something like:

y=[y,[4 zeros(1,(g-1))] ];

That gets rid of the error but there are other problems.

Work through your loops by hand - pick c=1 and choose 0 so that p=[-5,0,3] and see what happens. Make sure it's what you want to happen.
What happens if the user chooses break point positions out of order? i.e. if c=2, and the first point is 2 and the second is -1?
What happens if the user chooses non-integer break point positions?
I'm guessing you'll work out how to build a horizontal axis later?

-------------------------

[*] Shouldn't that be by Monsieur (Simon) Dupont for French? IIRC: "Simone" is the feminine spelling in French as it is in English so you are kinda implying that you think I'm a girl? Mind you - if I'm an honorary woman then I get to be "right" don't I so... no complaints there ;)

It is masculine in Italian though - for "Signor (Simone) Ponte" or something(?)
 
Last edited:
  • #5


Hello,

Concatenating signals in Matlab can be done using the "cat" function. This function combines arrays of the same type and dimension into a single array. In your case, you can use the following code to concatenate your signals:

A = cat(2,impulse,ramp,sinusoidal,dc,exponential);

Where "impulse", "ramp", "sinusoidal", "dc", and "exponential" are the arrays representing each type of signal, and the number 2 indicates that you want to concatenate the signals along the second dimension (i.e. horizontally). You can also use the "vertcat" function to concatenate signals vertically.

Additionally, make sure that all your signals have the same number of elements before concatenating them. If you are still having trouble, please provide more information about the error you are receiving and the specific code you are using. Good luck with your project!
 

1. What is the purpose of concatenating signals on Matlab?

The purpose of concatenating signals on Matlab is to combine two or more signals into a single signal. This allows for easier manipulation and analysis of the signals as a whole, rather than separately.

2. How do I concatenate signals on Matlab?

To concatenate signals on Matlab, you can use the "cat" function. This function takes in the signals as inputs and combines them into a single signal. You can also use the "horzcat" or "vertcat" functions for horizontal or vertical concatenation, respectively.

3. Can I concatenate signals of different lengths on Matlab?

Yes, you can concatenate signals of different lengths on Matlab. However, the signals must have the same number of channels. If the signals have different lengths, the shorter signal will be padded with zeros to match the length of the longer signal.

4. What are the benefits of concatenating signals on Matlab?

Concatenating signals on Matlab allows for easier data manipulation, analysis, and visualization. It also reduces the amount of code needed to work with multiple signals, making it more efficient and organized.

5. Can I concatenate more than two signals on Matlab?

Yes, you can concatenate more than two signals on Matlab. The "cat" function can take in multiple signals as inputs and combine them into a single signal. However, the signals must have the same number of channels for successful concatenation.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
738
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
Back
Top