Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I need to calculate the difference between values in a matrix without using the diff command. Is this done with a loop? I've tried:
for i=1:size(rho,2);
dz(:,i)=rho(:,i+1)-rho(:,i);
end
But obviously this wont work as the loop tries to continue beyond the the size of the matrix, how can this be done?
cheers
0 Kommentare
Antworten (1)
Andrei Bobrov
am 7 Nov. 2011
please read doc diff
e.g.
rho = randi(124,6)
dz = diff(rho,1,2) % in your case
2 Kommentare
Walter Roberson
am 7 Nov. 2011
We cannot really advise you how to proceed without knowing more about the mathematics involved.
Specifying that you want differences between adjacent elements is inherently going to get you a smaller matrix, unless you define the difference carefully. For example, you can get an equal sized matrix if you define the difference as:
- absolute value of the forward difference for the left edge
- absolute value of the backward difference for the right edge
- maximum (or minimum) of the absolute value of the forward and backward difference for any interior point
But of course whether that makes any sense for what you are doing, we do not know.
If you tack on an extra row than you end up with a distortion along that edge. That could be important. Or not. We don't know.
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!