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 日

0 投票

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 件のコメント

Chanaka Navarathna
Chanaka Navarathna 2019 年 1 月 27 日
編集済み: Chanaka Navarathna 2019 年 1 月 27 日
Thank you! I think it is working. Do you think it is reasonable to use it for following code?
N = 10000;
E = 10000;
C = 10*10^-6;
Q = 0.6;
f = 1/100;
l = 1;
Counting_Noise = 100;
Ncount=N+randn(N,1)*100;
Ndet = 2.303*Ncount*Q*E*C*l*0.01;
NZ=Counting_Noise+randn(Counting_Noise,1)*20;
hold all
for i=1:Ndet %(Signal)
for b = 1:NZ %(Noise)
Signal_to_Noise_Fl=i./b;
plot(i, Signal_to_Noise_Fl,'pg')
end
end
hold off
Chanaka Navarathna
Chanaka Navarathna 2019 年 1 月 27 日
I have expanded the code a littlebit to create two separate graphs. Again it gives me empty graphs or graphs with one data point.
subplot(2,1,1);
plot(i, Signal_to_Noise_Fl, 'pg');
xlabel('Signal');
ylabel('SNR');
subplot(2,1,2);
plot(b, Signal_to_Noise_Fl, 'pg');
xlabel('Noise');
ylabel('SNR');
end
end
hold off
Star Strider
Star Strider 2019 年 1 月 27 日
As always, my pleasure!
I do, although I am not certain what you want to do.
Here is another option:
N = 10000;
E = 10000;
C = 10*10^-6;
Q = 0.6;
f = 1/100;
l = 1;
Counting_Noise = 100;
Ncount=N+randn(N,1)*100;
Ndet = 2.303*Ncount*Q*E*C*l*0.01;
NZ=Counting_Noise+randn(Counting_Noise,1)*20;
for i=1:numel(Ndet) %(Signal)
for b = 1:numel(NZ) %(Noise)
Signal_to_Noise_Fl(i,b)=Ndet(i)./NZ(b);
end
end
figure
plot(Signal_to_Noise_Fl','-g')
Experiment to get the result that you want.
Chanaka Navarathna
Chanaka Navarathna 2019 年 1 月 27 日
What I am looking for is to plot
1)Signal_to_Noise_Fl vs. Signal
2)Signal_to_Noise_Fl vs. Noise
in two separate graphs.
The code you have suggested generates a graph for 100 different iterations of Signal_to_Noise_Fl calculation I guess. Isn't it? Sorry, I am a begginer and I probably might be asking ignorant questions.
Star Strider
Star Strider 2019 年 1 月 27 日
Try this:
N = 10000;
E = 10000;
C = 10*10^-6;
Q = 0.6;
f = 1/100;
l = 1;
Counting_Noise = 100;
Ncount=N+randn(N,1)*100;
Ndet = 2.303*Ncount*Q*E*C*l*0.01;
NZ=Counting_Noise+randn(Counting_Noise,1)*20;
for i=1:numel(Ndet) %(Signal)
for b = 1:numel(NZ) %(Noise)
Signal_to_Noise_Fl(i,b)=Ndet(i)./NZ(b);
end
end
figure
subplot(2,1,1)
plot(Ndet, Signal_to_Noise_Fl', '.g')
xlabel('Signal')
ylabel('Signal-to-Noise')
title('Signal-to-Noise vs. Signal')
subplot(2,1,2)
plot(NZ, Signal_to_Noise_Fl, '.g')
xlabel('Noise')
ylabel('Signal-to-Noise')
title('Signal-to-Noise vs. Noise')
Chanaka Navarathna
Chanaka Navarathna 2019 年 1 月 27 日
It gives me this error
"Error using plot
Vectors must be the same length."
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 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by