Subtract values of a row vector to each column of a matrix.
    9 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Giuseppe
 el 26 de Jul. de 2018
  
    
    
    
    
    Respondida: Brooks Li
 el 5 de Mzo. de 2022
            Hello guys,
I have written a small code attempting to remove an offset from a set of signals stored in a matrix. I need to subtract for each value of a column of a matrix (120x10) the value contained in a single row vector (1x10). Basically each column of the matrix represents an independent signal.
I have put together some code but I'm not obtaining what expected.
Here 'data' is a matrix (120x10) whereas 'columnMeans' is a row vector (1x10). Each column of the row vector should be used for the subtraction of the corresponding column of the matrix. I'm not even sure whether for loop is necessary.
for i=1:10
data_new=data-columnMeans(i)
end
0 comentarios
Respuesta aceptada
  madhan ravi
      
      
 el 26 de Jul. de 2018
        Hi, I have attached an example:
columnMeans=randi([1 10],1 ,10);
data=randi([1 30],120,10);
[m,n] = size(data);
for i=1:m
    data_new(i:i,:)=data(i:i,:)-columnMeans(:,:)
end
data_new
size(data_new)
0 comentarios
Más respuestas (2)
  Gul Rukh Khan
 el 8 de Dic. de 2019
        Thanks, for the Answer,
I have another problem, I want to subtract 1st pixel value in 10x10 matrix from the next to the right as well as to the down pixel. and also to store it in r(x,y) matrix. How, I will do it? Please, this command, is not working properly.
for x=1:10
for y=1:10
       r (x,y) = (aa(x,y)-(aa(x,y)));
       x=x+1;
   end
end
0 comentarios
  Brooks Li
 el 5 de Mzo. de 2022
        No need to do the for loop.
Just
data_new = data - columnMeans;
will simply work.
0 comentarios
Ver también
Categorías
				Más información sobre Logical en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!