フィルターのクリア

for loop increment problem

1 回表示 (過去 30 日間)
Nouha Amine
Nouha Amine 2022 年 5 月 26 日
編集済み: KSSV 2022 年 5 月 26 日
Hello,
I am having a problem with my for loop,
I want it to generate every possible plot for r between 2.1 and 4 with 0.1 increment,
what am I doing wrong
'I am a beginner
clc
clear
% first we should note that this is a log-log plot
% Let's introduce k first
k = logspace(0, 4, 100); %connectivity of a vertix
PK1= k.^(-2.9+0.1); % for gamma equal 2.9-0.1
PK2= k.^(-2.9-0.1); % for gamma equal 2.9+0.1
for r=2.1:4
PK3=k.^(-r); %for gamma changing between 2.1 and 4
loglog(k,PK3,'s')
hold on
loglog(k,PK1,'s') % plot with squares that describe gamma=2.9-0.1
loglog(k,PK2,'o') %plot with rounds that describe gamma=2.9+0.1
loglog(mean(k),'--', 'LineWidth',5)
hold off
r=r+0.1;
end
  1 件のコメント
Faruk Ortes
Faruk Ortes 2022 年 5 月 26 日
編集済み: Faruk Ortes 2022 年 5 月 26 日
Dear Nouha,
Please try r=2.1:0.1:4 instead of r=2.1:4. You should use your increment value in for loop.
Keep up good work

サインインしてコメントする。

回答 (1 件)

KSSV
KSSV 2022 年 5 月 26 日
編集済み: KSSV 2022 年 5 月 26 日
clc
clear
% first we should note that this is a log-log plot
% Let's introduce k first
k = logspace(0, 4, 100)'; %connectivity of a vertix
r = 2.1:0.1:4 ;
PK1 = k.^(-r) ;
loglog(k,PK1)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by