Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

I have to vectorize the following code. I have tried using vectorization but can't get the output as I require.

1 vue (au cours des 30 derniers jours)
A = rand(100,1);
B = cell(length(A),2);
%% for loop (working)
for i = 1:length(A)
B{i,1} = A(i); % appending all the values of A in 1st column of cell
end
index = [1 4 6 10 15 19 26 43];
for j = index
B{j,2} = [B{j,2};A(j)] % appending all the values of A in 2nd column of cell
end
%% Vectorization (not working)
ii = 1:1:length(A) % array with uniform spacing
B{ii,1} = A(ii,1);
index = [1 4 6 10 15 19 26 43]; % array with selected indices
B{index,2} = [B{index,2}; A(index)]

Réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by