Turning a 1x3001 array into a 14x3001 array to make two things the same size and perform math on them...
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
Super new with MatLab so apologies for ignorance, it's for a course on Signals.
I am trying to compare the ground truth signal, the single frequency, which has 3001 samples (it is a 1x3001 row vector) to a 14x3001 array. I want to add the abs value of the 1x3001 vector to the abs value of the each of the 14 rows of the array.
So I would like to repeat the 1x3001 row 14 times to add the abs value of that to the 14x3001 array.
Stuck on how to get the 1x3001 to repeat 14 times and turn into its own 14x3001 array to work with the second array...
Element by element and then graph it later, with maybe a stem...
Thanks for any and all help...
0 commentaires
Réponse acceptée
Voss
le 7 Sep 2024
Modifié(e) : Voss
le 7 Sep 2024
You don't have to explicitly repeat the 1x3001 row vector 14 times in order to add it to the 14x3001 matrix.
Here's an example of adding a 1x5 row vector to a 3x5 matrix to illustrate the syntax:
v = 1:5
m = rand(3,5)
result = v+m
However, if you need to create a matrix consisting of multiple copies of a row vector for some other purpose, here's one way to do that:
vv = repmat(v,3,1)
And another way:
vv = v(ones(3,1),:)
And adding that matrix to the other one works as expected
result = vv+m
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!