How can I plot scatter graphs in a for loop?

조회 수: 11 (최근 30일)
Lala0099
Lala0099 2019년 11월 11일
댓글: Rik 2022년 4월 8일
I have a large data set. I am trying to use a for lop, to be able to select which coloumn i want to keep and which ones i want to discard, all depending on the user input.
I managed to do that part, i believe.
Now I am trying to get an average value for each coloumn and plot the results in a scatter graph. I tried to do this using a for loop.
But there is only one data set that appears on my scatter graph, so I assume it cancels the ones that were before that last point. I used hol all, hold on and draw now, but could not get it to work. Also I would like add a line of best fit for the scatter graph for each data set and save slope and intercept numbers in a table.
I managed to do do the line of best fit and slope, intercept before, but not since I am trying to use for loops, so I put my old code segments in a comented out section.
In the first version of the code, i just determined the coloumns ( channels ) i want to use in the code, not depending on user input.
I cannot upload the excel file that I use, because it is too big. i tried to compress, but did not work

답변 (1개)

David Hill
David Hill 2019년 11월 11일
Assume you have your data in a matrix, M. Assume you want a scatter plot of the column vs. mean of each column.
scatter(1:size(M,2),mean(M));
  댓글 수: 4
Helder Maranhão
Helder Maranhão 2022년 3월 29일
편집: Rik 2022년 4월 8일
Hi. I think understand the question. I have the same issue.
Imagine that you have a for loop
n=1
for k=1:20
y=n+1
n=n+1
end
scatter(k,y)
So imagine that you want to plot the y for each k from 1 to 20.
But in Matlab it will appear the last value for k.
How can we plot k from 1 to 20?
Could someone help?
Thank you
Rik
Rik 2022년 4월 8일
@Helder Maranhão your code overwrites the value of each parameter every iteration. You should learn to use arrays.

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

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by