How to plot a simple expression in matlab

Hello everyone Please I need your help..I'm new in matlab and i have problem in plotting curves..... I have a curve already plotted and i have to reproduce it.I have this data : the function is y=1/(2^(K-1)) (K var) The x axis is [0:5:50] The y axis is [10^(-5):10^(-1):10^(0)] the figure is below.I have to plot the curve for "OW" (blue sky) Anyone please can help me and thanks in advance.

댓글 수: 5

Rik
Rik 2017년 11월 14일
The semilogy function will help here. The rest is basic Matlab syntax for which you should look at a tutorial. A free one by Mathworks is available here. Other, more general tips can be found here.
lakom Mariem
lakom Mariem 2017년 11월 14일
Ok Thanks a lot. I tried with this code but it desn't give what i want function y = Cesow(K)
for K=1:4; y= 1/(2^(K-1)); end x=[0:5:50]; %plot(x,y); semilogy(y); end Would you please tell me wher's the mistake
lakom Mariem
lakom Mariem 2017년 11월 14일
I tried also with this
function y = Cesow(K) y= 1/(2^(K-1)); end
and in prob.m, i have : clear all; close all; clc; p=1000; p= 10^(p/10); indx=(0:5:50); K=1:10; f1=@(x) Cesow(1); f2=@(x) Cesow(2); f3=@(x) Cesow(3); f4=@(x) Cesow(4); for i=1:size(indx,2) %for i = 1:numel(indx) %size(indx) %indx(i); Vc1(i)= f1(indx(i)); Vc2(i)= f2(indx(i)); Vc3(i)= f3(indx(i)); Vc4(i)= f4(indx(i)); end plot(indx,Vc1,'--'); %hold on; plot(indx,Vc2,'--'); %hold on; plot(indx,Vc3,'--'); %hold on; plot(indx,Vc4,'--'); %hold on; leg=legend('OW (Asym. approx.)'); set(leg,'location','best') set(gca, 'YScale', 'log') xlabel('P [dB]'); ylabel('secrecy outage probability'); grid on I cannot find the real method of how to do it..Please i need your help
Rik
Rik 2017년 11월 14일
편집: Rik 2017년 11월 14일
The best help I can give you is to tell you to do a tutorial before you try some random code you found. That last link I gave you also contains helpful advice (like e.g. to select you code and hit the {}Code button to correctly format code).
You should not use plot inside a loop if you want to plot a single line.
I don't know what your goal is with sending me the e-mail you did. You're the one asking for help. You've been working with Matlab for at least 8 months now, so you had time enough to learn the tool you are using. The code below should be trivial to come up with if you have done any tutorial worth its salt.
K=1:4;
y= 1./(2.^(K-1));
semilogy(K,y,'--')
ytickvals=10.^(-5:1:0);
yticks(ytickvals)
ylim([min(ytickvals) max(ytickvals)])
grid on
If you want any help from someone, I would suggest not hitting send on an e-mail that contains a sentence like "Me too i can advise you to learn english so you can write a simple sentence correctly."

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

답변 (0개)

카테고리

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

제품

질문:

2017년 11월 14일

댓글:

Rik
2017년 11월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by