Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Shubham Burde
Shubham Burde 2020 年 2 月 17 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by