multiplying with a with a scaler in a vector element at regular interval
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Aman
le 28 Juin 2023
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!
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!