creating a vector from data in a large array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello all,
Thanks for this resource, it has been helpful reading but I am now at the point I need to ask a question......
I have a very large array that I need to use periodic values from to create a vector (still a large vector)
my problem, example, I need to take the difference between two sets of numbers and divide them (finding the gradient) and then repeat this every 65 lines till the end of the array, creating a vector.
eg. ((3,2)-(2,2))/((3,4)-(2,4)) this is the first entry of the vector
((68,2)-(67,2))/((68,4)-(67,4)) this is the second entry of the vector
((133,2)-(132,2))/((133,4)-(132,4)) this is the third entry of the vector
((198,2)-(197,2))/((198,4)-(197,4)) this is the forth entry of the vector
and so on and so on, every 65 lines until the end of the 65000 x 8 array creating a 1000 X 1 vector
The array is called AvD_pi_tr_64_7900
I hope someone can help as I feel this is not as hard as I am making it but just don't know the terminology to search for within the sight.
Thank you in advance,
all the best,
Leon
0 Kommentare
Antworten (3)
Image Analyst
am 16 Mär. 2018
How about a simple for loop:
AvD_pi_tr_64_7900 = rand(65000, 8); % Whatever...sample data.
counter = 1;
for row = 3 : 65 : size(AvD_pi_tr_64_7900, 1)
output(counter) = (AvD_pi_tr_64_7900(row, 2) - AvD_pi_tr_64_7900(row - 1, 2)) / ...
(AvD_pi_tr_64_7900(row, 4) - AvD_pi_tr_64_7900(row - 1, 4));
counter = counter + 1;
end
By the way, 65000 by 8 is not that large.
0 Kommentare
dpb
am 16 Mär. 2018
Bearbeitet: dpb
am 17 Mär. 2018
Start with the "brute force, straightahead" solution...
dN=65; % the magic number between observations--don't bury inside code
iy1=2; iy2=4; % the magic numbers of target columns for difference
[nr,~]=size(x); % number rows in array
ix=3:dN:nr % index vector to rows needed
v=(x(ix+1,iy1)-x(ix,iy1))./(x(ix+1,iy2)-x(ix,iy2)); % compute the derivative vector
ERRATUM
I just realized I forgot to do the differences previously, sorry...see above
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!