I understand you get v = (v(1),v(2),...v(n)) to compare with w =(w(1),...,w(m)).
These vectors are in different dimensions n and m.
You can always pad the shortest one with zeroes, but does it respect the meaning of your problem?
If you want to see if the vectors have similar direction, compute cos(v, w) = v. w/(norm(v). norm(w)). The vector have close direction if the cosine is close to 1, almost opposite if close to - 1...
In Physics, vector is a quantity that has both magnitude and direction. In MATLAB, vector can be 1-D array with set of values e.g., [2.1, 4, 8.3, 7] or it can be a vector like Physics.
I think you have to explain your question with some more details such as:
1) What do you mean by vector? Give an example.
2) What do you mean by finishing loop?
3) What do you mean by obtain from the same procedure?
Hi, you can "compare" two vectors by making them the same lenght.
if you have vector A = [ 2.1, 3.02, 1.0, 0] and vector B=[1.12, 1.5] vector's A dimension is [1,4] (one row, & 4 elements) and vector's dimension is B is [1, 2] (one row & 2 elements).
To compare them you have to make them equal in dimensions: so you should "create" a meaninful vector B1 that contains the same values as vector B but you have some "explanation" why the 2 elements of the "original" vector B are "missing."
1. hypothesis both vectors contain measurements on electrical voltage and there are 4 locations where 2.1 V, 3.02V, 1.0 V and 0 V were measured; 5 min later an electrician measured the voltage at the same locations and obtain vector B and placed 1.12V and 1.5V & he "forgot" to write down the values of the remaning two locations alpha and beta.
2. You have an option to add either two zeroes for the alpha and betha values, or use two random values that are likley to be measured taken by electrician.
3.I would say, I would add in the new "made up" vector B* additional 2 values that are random values beween 0 to 3.02 as it seems that vector A gives us some "prior knowledge" about the values. You should decide how to "fill up" for that "prior Knowledge."
4. In that case I can argue (an I can decide) that it is possible that the technition measured two additiona values of 0.5V and 2 V and the newly made vector isB*=[1, 4, 0.5, 2] which "matches" the dimensionality to vector A.
Therefore, I can compare Vector A and Vector B* and say that this is based on some "guess" based ion prior estimate of iven by vecto A.
Alternativley, you can add average values (sum (A)/4) ((2.1+ 3.02 + 1.0 + 0)/4) in B**=[1, 4, 1.53, 1.53]
Or, you can add Zeroes
B***=[1, 4, 0, 0].
Therefore - the main thing is to make the dimesions of the vectors equal, depending of the practical rationale of the problem. You are the one that will define what is the most likley to be close the the "truth" in this "thinking" experiment.
Dear Renaud Di Francesco , Murtaza Khan and Viara Van Raad
Thanks for your answers. but I think I define my problem badly.
I have 2 time domain signal that they were store in the 2 vectors with different length. and I want to compare them to find that they are close together or no.
I find a way to compare that by using and FFT algorithm to make 2 new vector with same length. Am I right?
OK, you want to compare the vectors that are result from an FFT. In order you have 2 vectors with the same dimensions, for the FFT part - you have to define the same number of frequencies for the FFT decomposition and run the FFT transformation of the original vectors (containing the signals that you want to decompose) based on this. The end result (post FFT) should be two different vectors of FFT decomposed signals that have same dimensions.
I hope that this is more relevant to what you wanted to clarify in the very beginning, right?
You form the autocorrelation matrix of v :Cor(v) resp. of w, Cor(w). Such matrices diagonalise.
You find their eigenvalues, and you compare them... You can observe the sum of squares of eigenvalues (energy).
Cor(v) is defined as c(i, j) with c(i, j) =
Where T(i) shifts coordinates by i in circular form:
T(i). v=(v(1+i), v(2+i)...v(n),v(1)...,v(i))
Cor(v) is a Gram-Schmidt matrix.
This comparison of Cor(v) and Cor(w) described above (eigenvalues, energy) is very robust and encompasses frequency domain aspects (texture, modes of resonators... Etc)
I am very happy to have found this way for you.
Naturally, the other suggestions are valid, but this one sticks to the physical nature of these two signal vectors...
I agree with Erik: you can take the shortest vector, say w =(w(1)...w(m)) and "slide it" over the longer one say v =(v(1)...v(n)), by a space of k. At each step you compute the scalar product of the m dimensional sub vectors: w(1).v(1+k) + w(2).v(2+k)+... +w(m+k). v(m+k).
Maximising over the allowed k (k in [0,n-m]) you find a k* (one or more).
Then the highest similarity between a m-dimensional "window" of v is found, this is the correlation of those two signals.
It's used in radar, pattern matching, etc...
The autocorrelation method I gave earlier is more intrinsic on the properties of v and w (frequency domain, etc...), but this one here is "relative", a form of tangent space view
Yes, I like the suggestions of you Renaud and Erik, but this is "solving" the problem for the person, I think it is better for the person to discover in her/his own way how to reach the solution. Also it wasn't specified what should be compared in the vectors? Was it a programming question or, a question of signal processing. yes, if I want to compare the contents and the correlation of the vectors - it would be good to ask for the corresponding covariance matrices, power content, variations etc. But my understanding is that is was a simple "how to pass numbers through a loop" I think we should demand a bit more explanation next time before a question is asked.
@Viara: I have observed that people ask a question on researchgate because they are blocked in their research project.
There are many questions like "how do I do this in Matlab" which have no interest to me.
Other, more interesting questions are for getting out of a dead-end. In that case knowing that a solution exists will help the researcher to be comforted that after all it's not a dead-end, and maybe he or she will find yet another (and better) way around the obstacle.
Necessity is the mother of invention. Giving a hint is like impulsing an initial speed. Then everything gets moving.
We engineers face ill conditioned problems everyday.
Renaud Di Francesco Yes, sure @ Dr. R. Di Francesco: I am absolutely adamant that researchers and engineers should be very thankful for your generosity and the generosity of some others (giving them a ready solution & a code), however, some people may not be very grateful & they "play tricks." I have seen developing ideas (based on hints and ideas given casually) with a very low "threshold" of a modification (by more entrepreneurial types of people), and no providing the right kudos, which is the least that one wants.
Thank you, see: the answer was much simpler than the one that we anticipated :-). It is good that you have provided us with a feedback and we know better your aim of the question.
I suspected that this is more about the constructing the code (e.g. feeling out the numbers periodically in that case until the vector have same length) rather than the what the signal contains. Cheers, Viara
Hi Alireza, it makes sense, and your exploration has surely broadened the horizon of possible tools of interest.
As engineers or applied scientists, it's only when addressing the problem fully than one can assess if the tool is fit for this specific purpose, which you have done. Sound approach, well done!