Storing values from a for loop and plot

조회 수: 10 (최근 30일)
Chanaka Navarathna
Chanaka Navarathna 2019년 1월 26일
댓글: Chanaka Navarathna 2019년 1월 28일
I need to store the data generated for "Signal" and "Noise" and plot "Signal_to_Noise_Fl" vs. "Signal" for all the iterations. (Ndet and NZ are coming from some random numbers generated from randn function)
I keep getting blank plots when I plot either inside or outside the loop. Any suggestion?
for i=1:Ndet %(Signal)
b = 1:NZ; %(Noise)
Signal_to_Noise_Fl=i./b
end
  댓글 수: 2
Matt Gaidica
Matt Gaidica 2019년 1월 26일
You need to add the code where you're trying to plot the values.
Chanaka Navarathna
Chanaka Navarathna 2019년 1월 26일
for i=1:Ndet %(Signal)
for b = 1:NZ %(Noise)
Signal_to_Noise_Fl=i./b;
plot(Signal_to_Noise_Fl)
end
end
this is what I did and it gives a blank plot

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

채택된 답변

Star Strider
Star Strider 2019년 1월 27일
Plot with a marker, and use the hold function:
Ndet = 10;
NZ = 10;
hold all
for i=1:Ndet %(Signal)
for b = 1:NZ %(Noise)
Signal_to_Noise_Fl=i./b;
plot(Signal_to_Noise_Fl, 'pg')
end
end
hold off
  댓글 수: 8
Star Strider
Star Strider 2019년 1월 27일
It worked for me.
‘Signal_to_Noise’ is a (10000 x 100) double array, ‘Ndet’ (that you describe as ‘Signal’) is a (10000 x 1) double array, and ‘NZ’ (that you describe as ‘Noise’) is a (100 x 1) double array. They should all plot correctly as in my code, and they did for me (in R2018b).
I have no idea what the problem is.
The data I plotted with the code I posted:
Chanaka Navarathna
Chanaka Navarathna 2019년 1월 28일
I am using version 2016. May be because of that. I will give it a try again.
Thank you.
If possible please help me for my other questions.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by