Turning a 1x3001 array into a 14x3001 array to make two things the same size and perform math on them...
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2024-9-7
编辑:Voss
2024-9-7
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!