How to Loop to plot histogram and line plot?
    11 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Arshey Dhangekar
 el 3 de Jun. de 2021
  
    
    
    
    
    Comentada: Constantino Carlos Reyes-Aldasoro
      
 el 3 de Jun. de 2021
            Hello I want to use loop to plot histogram and line plot. I am getting error
Temp=readtable('inst0 138.221.155.178 11_19_2020 06_55_37 1.csv')
for i=4:8;k=1:2
        subplot(1,2,k)
        plot(Temp(:,3),Temp(:,i)) 
end
for p= 4:7
    subplot(2,2,k)
    histogram(Temp.[p])
end
0 comentarios
Respuestas (1)
  Constantino Carlos Reyes-Aldasoro
      
 el 3 de Jun. de 2021
        The following is not clear and most probably your error:
for i=4:8;k=1:2
        subplot(1,2,k)
        plot(Temp(:,3),Temp(:i)) 
end
Are you trying to have 2 loops there? What your code is doing is the following:
for i=4:8
    k=1:2
    subplot(1,2,k)
    plot(Temp(:,3),Temp(:i)) 
end
It runs a loop on i, then it assigns k a range between 1 and 2, then calls a subplot with the value of k, which prompts an error as you should have a single value.
Perhaps you need the following:
for i=4:8
    for    k=1:2
        subplot(1,2,k)
        plot(Temp(:,3),Temp(:i))
    end
end
6 comentarios
  Constantino Carlos Reyes-Aldasoro
      
 el 3 de Jun. de 2021
				I have not tried to define any method, just to point out your error here:
plot(Temp(:,3),Temp(:i))
This will not work, it requires a comma between the : and the i like this
plot(Temp(:,3),Temp(:,i))
Ver también
Categorías
				Más información sobre Histograms 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!

