How can i fit a linear line to a scatter plot knowing the intercept?
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Joseph
 el 12 de Jul. de 2018
  
    
    
    
    
    Respondida: Star Strider
      
      
 el 12 de Jul. de 2018
            Hi, I have an array lets say, E(500,2) and I want to fit a line to scatter plot of E (scatter(E(:,1), E(:,2))), but the intercept for this fit is known within the error. if i use polyfit(E(:,1),E(:,2),1), i cannot determine the intercept. is there any way that I can fit a linear line with a fixed intercept?
thanks in advance
0 comentarios
Respuesta aceptada
  Star Strider
      
      
 el 12 de Jul. de 2018
        See if this does what you want:
E = rand(500, 2);                                       % Create Data
x = E(:,1);                                             % Create Data
y = E(:,2);                                             % Create Data
intercept = 0.7;                                        % Create Data
B = x(:) \ (y(:)-intercept);                            % Estimate Parameters (Linear Model)
yfit = [x(:) ones(size(x(:)))]*[B; intercept];          % Fit Data
figure
plot(x, y, 'pg')
hold on
plot(x, yfit, '-r')
hold off
0 comentarios
Más respuestas (0)
Ver también
Categorías
				Más información sobre Scatter Plots 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!

