Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
I have to vectorize the following code. I have tried using vectorization but can't get the output as I require.
조회 수: 1 (최근 30일)
이전 댓글 표시
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)]
댓글 수: 0
답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!