how compare two cplumns from different matrix;

1 次查看(过去 30 天)
Hi all!
I have two matrix:
First [A] has 2 columns and 4 lines:
107,407870375000 377,600000000000
107,415393500000 375,700000000000
107,498171291667 381,900000000000
107,556215291667 387,100000000000
Second [B] has 3 columns and 22 lines:
107,235567125000 343,885429687500 19,7753906250000
107,244513875000 377,138398437500 12,7882812500000
107,255046291667 377,455351562500 11,0281250000000
107,264641208333 382,923242187500 7,95039062500000
107,275659708333 385,504140625000 5,87578125000000
107,284224541667 385,393125000000 6,05664062500000
107,295682875000 394,200000000000 4,95234375000000
107,304583333333 389,552226562500 4,26210937500000
107,313958333333 389,240390625000 4,78945312500000
107,322245375000 387,623867187500 4,27656250000000
107,331585666667 385,900468750000 3,87921875000000
107,338703708333 389,454609375000 3,64628906250000
107,349247666667 387,801601562500 3,59406250000000
107,356365750000 388,281718750000 3,36320312500000
107,366388875000 384,638125000000 3,57777343750000
107,373182875000 390,168437500000 3,32972656250000
107,383472208333 382,523437500000 3,20972656250000
107,391018500000 382,931054687500 3,27320312500000
107,400300916667 383,220273437500 3,18894531250000
107,407222208333 379,468515625000 3,48558593750000
107,416759250000 386,672070312500 3,06492187500000
107,423726833333 381,518359375000 3,18691406250000
I want for each value from the matrix A and column 1 to find the nearest value from matrix B and column 1.
Then, I need to find mean value from the matrix B (columns 1,2 ) from the value i found previously +- 0.015.
For example, if i take the value 107.40787 from the [A], the nearest in [B] is 107,407222.
107.40722 +- 0.015 are the values from B:
107,400300916667 383,220273437500
107,407222208333 379,468515625000
107,416759250000 386,672070312500
Then, I will find means from these two columns and compare the values.
Thank you!!
  3 个评论
Giorgos Papakonstantinou
Thodoris I know how to read. Don't copy/paste the 2nd part of the question. It doesn't help me.
You need to find the mean value from the matrix B(:,1:2).
  • Mean in which dimension (along the row or column)?
  • What is the value i you found previously?
  • +/- 0.015?
Thar
Thar 2015-2-28
First I found the nearest values. Τhis is ok. Then, I want to these values from matrix B(:,1) I found and for the values which fluctuate 0.015 from these values to found the mean value.
For example, if i take the value 107.40787 from the [A], the nearest in [B] is i=107,407222. The values in B(:,1) which fluctuate 0.015 from the i are
107,400300916667 383,220273437500
107,407222208333 379,468515625000
107,416759250000 386,672070312500
I took and the corresponding values in B(:,2).
Now i want to find mean from these values. One from 1st column and one to the second column.
I hope this time to done understood.
Thank you!

请先登录,再进行评论。

采纳的回答

Giorgos Papakonstantinou
编辑:Giorgos Papakonstantinou 2015-3-1
Hallo Thodoris.
[~, ii] = min(abs(bsxfun(@minus,A(:, 1)',B(:,1)))); % These are the row indexes of B(:,1) which are nearest to each value of A(:,1)
B(ii,1) % for each element of A(:,1) these are the nearest values of B(:,1).
f = @(x, y) abs(x - y)<0.015; % create anonymous function to find which values fluctuate 0.015
idx = bsxfun(f, B(:,1), B(ii,1)');
Col1mean = ones(size(idx, 2), 1); % preallocate
Col2mean = ones(size(idx, 2), 1);
for ii = 1:size(idx, 2)
Col1mean(ii) = sum(B(:,1).*idx(:,ii), 1)./sum(idx(:,ii), 1);
Col2mean(ii) = sum(B(:,2).*idx(:,ii), 1)./sum(idx(:,ii), 1);
end
For the last part I have to cite the solution of Jan Simon from here. You can also find very good answers in this link on how to mean a matrix columnwise based on another logical matrix.
  2 个评论
Thar
Thar 2015-3-1
idx = bsxfun(f, B(:,1), B(ii,1)')
What is B(ii,1)?
I have not designate the ii here.
Thank you!
Giorgos Papakonstantinou
:-). I corrected my answer. In the first two commands I replaced idx with ii.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by