AVOID FOR LOOP for changing size vector
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
gabriele fadanelli
il 27 Mar 2020
Risposto: Abhisek Pradhan
il 30 Mar 2020
I need to solve this problem without a for loop:
B= (1:20)
A = [];
A(1) = 1/(1+B(1));
for k = 2:length(B)
A(k,1) = (1-B(k)*sum(A))/(1+B(k));
end
i.e. I need to know if it is possible to get information from previous calculation to create a vector, but without a for loop. Thanks.
2 Commenti
Adam
il 27 Mar 2020
Can't think if there is a way to avoid a for loop for that, but the vector size certainly does not need to change. You can presize A as
A = zeros( size( B ) );
Risposta accettata
Abhisek Pradhan
il 30 Mar 2020
I could understand you want to avoid use of loop. This can be done using vectorization.
Refer the following link which has few examples on how to do vectorization.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Multidimensional Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!