Executing same function in different elements of an array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I have wrote a function for small calculation. And I have an array 'A' which has over 25000 elements. I would like to refer certain ranges like A(2500:2800), A(5000:5300) and so on.., execute above mantioned function on them. Also, getting separate outputs from each range of A that I have selected. I have tried using array fun but I couldn`t make it work.
Please give your recommendations in this case.
Thank you
0 Commenti
Risposta accettata
Stephen23
il 20 Mag 2020
Try something like this:
B = [2500,5000,...]; % begin indices
E = [2800,5300,...]; % end indices
N = numel(B);
C = cell(1,N);
for k = 1:N
V = A(B(k):E(k));
... do whatever with subvector V
C{k} = ... output of your code
end
2 Commenti
Stephen23
il 21 Mag 2020
Replace the definitions of B and C with
B = [10,30,50,70,90];
C = [20,40,60,80,100]);
These are supposed to be vectors of indices. You used them to extract elements of A before the loop, and then in the loop you used those extracted elements of A as indices into A... which is unlikely to be very useful.
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!