Executing same function in different elements of an array
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yanjika O
el 20 de Mayo de 2020
Comentada: Stephen23
el 21 de Mayo de 2020
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 comentarios
Respuesta aceptada
Stephen23
el 20 de Mayo de 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 comentarios
Stephen23
el 21 de Mayo de 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.
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!