creating a vector from data in a large array

조회 수: 1 (최근 30일)
Leon Newton
Leon Newton 2018년 3월 16일
편집: dpb 2018년 3월 17일
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

답변 (3개)

Image Analyst
Image Analyst 2018년 3월 16일
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.

dpb
dpb 2018년 3월 16일
편집: dpb 2018년 3월 17일
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

Leon Newton
Leon Newton 2018년 3월 16일
Thanks so much for both of the responses.
I can now do what I needed in this bit of my task.
All the best and thanks again.... :-)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by