How to find values in one vector that don't have corresponding values (in the same row) in another

5 visualizaciones (últimos 30 días)
Hi,
I have a very large dataset of sample measurements and I need to plot sample data but without the 'background' data, i.e. data that appears in the control samples. Here is an example of the data:
row a b c sample1 sample2 control1
1 5 2 1 236489 NaN 456932
2 8 3 0 NaN 278695 569202
3 12 8 2 NaN 332465 NaN
I have loaded the whole dataset as a tab delimited txt file and so each column of data is in a different vector. (NaN is where there was no value in the original tab file).
I need to plot a/b against c/b with the sample value on the z axis. I have managed to do this for all the values in the sample vector, but I need to remove all the sample values that have a value on the same row in the control sample. For example, if I want to plot the data for sample2 that does not occur in control1 I have this:
tdfread('file.txt');
ab = a(:,1)./b(:,1);
cb = c(:,1)./b(:,1);
sample2_without_control1 = setdiff(sample2,control1)
scatter3(ab,cb,sample2_without_control1)
What I would aim to plot is the a/b and c/b values but only from row 3 - as this is the only row in which there is data from sample2 but not control1. However setdiff doesn't work - I still need the value to be kept the same (i.e. as 332465) and not altered at all.
(I have thousands of rows of data like this, so I need a way to do this for entire vectors at once please!)
Thank you :)
  4 comentarios
Adam
Adam el 2 de Jul. de 2019
Which bit gives a binary output?
You will lose the exact positions for your
a(idx)./b(idx)
result, but these can just be reinserted into a full length vector of NaNs or whatever you want for the non-results again afterwards, using the same idx vector for their positions.
Jan
Jan el 2 de Jul. de 2019
I do not understand, what you are asking for. "setdiff doesn't work" - what does this mean? Of course setdiff is working.
You want to get the indices of some rows. So do not use a = setdiff(b,c) but the 2nd output also.
"I need to remove all the sample values that have a value on the same row in the control sample" - this might mean:
keep = not(ismember(sample1, control1) | ismember(sample2, control1));
ab = a(keep,1) ./ b(keep,1);
cb = c(keep,1) ./ b(keep,1);
scatter3(ab, cb, sample2(keep))

Iniciar sesión para comentar.

Respuestas (1)

SaiDileep Kola
SaiDileep Kola el 16 de Jul. de 2019
Hi Emily,
Please first find the indices of the matrix with control1 values as NaN using the following command:
indices = find(isnan(your_matrix(:,control1)) == 1)
You can also use the 'nansum' comment to add values of sample1 and sample2 in a row-wise fashion:
y = nansum(X,2) %2 is to add along column dim
X is your reformed matrix after removing rows with NAN values and containing only sample1 and sample2 columns
Now you can plot accordingly

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by