multiplying with a with a scaler in a vector element at regular interval
显示 更早的评论
I have a 15X1 size vector, i want to multiply with a scaler to the element of vector at a regular place i.e., 3, 6, 9, 12, 15
采纳的回答
更多回答(1 个)
Aman
2023-6-28
Hi,
To multiply specific elements of a 15x1 vector by a scalar at regular intervals (3, 6, 9, 12, 15), you can use indexing to access those elements and perform the multiplication.
Here's an example code snippet that demonstrates how to do this:
% Create a 15x1 vector
vector = (1:15)';
% Define the scalar value
scalar = 2;
% Specify the indices of the elements to be multiplied
indices = [3, 6, 9, 12, 15];
% Multiply the specified elements by the scalar
vector(indices) = vector(indices) * scalar;
Hope this helps!
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!