Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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

1 visualización (últimos 30 días)
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)]

Respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by