How to Loop to plot histogram and line plot?

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

답변 (1개)

0 개 추천

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

I want plot histogram using loop with title and legend
for k = 1:4
subplot(2,2,k)
histogram(Temp(:i))
xlabel('')
ylabel('')
end
you need to be clear on how you are using your variables, in the above, k is looping 1 to 4 and this is addressing the subplots 1 to 4, that is fine, but then
histogram(Temp(:i))
has 2 errors, i as a variable is not changing so you will be plotting the same and
Temp(:i)
does not work, that may be correct in Python but in Matlab it should be either (:,i) where you take all the rows and column i or if you want to take only part of a range it would be 1:i or i:end.
I am confused still could explain it in code ,Temp(:i)) will not work I want to plot from column 3 to 7 histrogram plot
d1=Temp(:,3) to d4=Temp(:,7)
for i=4:8
for k=1:2
subplot(1,2,k)
plot(Temp(:,3),Temp(:i))
end
end
notice the difference between Temp(:,3) and Temp(:3) or as it would be Temp(:,i) and Temp(:i)
I defined Temp as. I am trying to use your method I did not get histogram for column 4 to 7
Temp=readtable('inst0 138.221.155.178 11_19_2020 06_55_37 1.csv')
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))

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

제품

릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by