Command for picking two regular elements from a Vector
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a vector of size 30X 1
I want to pick up 1, 2, 4 , 5, 7, 8, 10, 11, ............28, 29.
please suggest me how can i proceed?
1 comentario
Respuestas (2)
Steven Lord
el 7 de Jul. de 2023
Use randperm to create shuffled indices then use that index vector to reorder your vector of data. I'll use a deck of cards:
values = ["Ace", 2:10, "Jack", "Queen", "King"];
suits = ["club", "diamond", "heart", "spade"];
cards = combinations(values, suits);
order = randperm(height(cards)); % Random ordering of 1:52
shuffledDeck = cards(order, :); % Use order as indices into rows of cards table
Let's look at the first few cards of the two decks. First the one in order:
head(cards)
Next the shuffled deck.
head(shuffledDeck)
While I used table arrays here (cards, shuffledDeck), the same technique (i.e. shuffledDeck = cards(order, :); ) applies to regular arrays as well.
Satwik Samayamantry
el 7 de Jul. de 2023
Hi Patel, as per my understanding you want to remove all multiples of 3 from your input vector. The following function should get your job done.
function outputVector = removeMultiplesOfThree(inputVector)
% Initialize an empty output vector
outputVector = [];
% Iterate through each element in the input vector
for i = 1:length(inputVector)
% Check if the current element is not a multiple of 3
if mod(inputVector(i), 3) ~= 0
% Append the element to the output vector
outputVector = [outputVector; inputVector(i)];
end
end
end
Hope this helps you!!
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!