How to perform operations on cell arrays?
Mostrar comentarios más antiguos
I have this section of code
V = cell(1,12);
for k = 1:12
V{k} = cumtrapz(A{k});
end
I now need to convert from a cummulative V to discrete instances of V. It should be noted that columns 1-3, 4-6, 7-9, and 10-12 are of the same size (1=2=3 /= 4, but 4=5=6 etc.). If, for example, A{1,0} = 0, A{1,1} = 1, and A{1,2} = 4, then V{1,1} = 1, and V{1,2} = 3. This operation needs to be performed throughout each cell in order to get velocities at a point instead of a running total.
3 comentarios
Rik
el 8 de Oct. de 2019
It is not clear to me what your terminology means. Could you provide more details about what you want as output? It sounds like you want something like cellfun, but I'm not sure what steps to suggest.
Adam Danz
el 8 de Oct. de 2019
"How to perform operations on cell arrays?"
cellfun()
Jesse Finnell
el 9 de Oct. de 2019
Respuesta aceptada
Más respuestas (1)
I found using trapz is a more intuative method. I used linear acceleration so it was easy to check. I think there is a more efficient way to do this, but I am not certain.
Here is the results.
a = [0:1:49]'; %a = acceleration
deltaV = zeros(1,numel(a))'; % memory pre-allocation
for k = 1:49
deltaV(1,k) = trapz(a(k:k+1,1)) % integral over 1 period
end
figure(1)
plot(a)
xlabel('time')
ylabel('acceleration')
figure(2)
plot(v)
xlabel('time')
ylabel('velocity')
figure(3)
plot(deltaV)
xlabel('time')
ylabel('Change in Velocity')
2 comentarios
Jesse Finnell
el 10 de Oct. de 2019
John Doe
el 10 de Oct. de 2019
Typo on my part in line 3. I've updated.
k = 1:50
Should have been
k = 1:49
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!