필터 지우기
필터 지우기

for loop not working????

조회 수: 1 (최근 30일)
Abu Zar
Abu Zar 2023년 3월 17일
편집: Bhanu Prakash 2023년 3월 17일
fidelities value does not change with different values of r.
i'm trying to get the different values of fidelity with different r values,and plot(fidelity,r).
  댓글 수: 1
Atsushi Ueno
Atsushi Ueno 2023년 3월 17일
편집: Atsushi Ueno 2023년 3월 17일
No, for loop is not working because the number sequence is not recognized as a column vector.
for r=0.01;0.02;0.03;0.04;0.05;0.06;0.07;0.08;0.09;0.10;
r
end
r = 0.0100
But this fixing does not work as you expected:
for r = [0.01;0.02;0.03;0.04;0.05;0.06;0.07;0.08;0.09;0.10;]
r
end
r = 10×1
0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000
It can be fixed as following:
for r = 0.01:0.01:0.1 % or r = [0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10]
r
end
r = 0.0100
r = 0.0200
r = 0.0300
r = 0.0400
r = 0.0500
r = 0.0600
r = 0.0700
r = 0.0800
r = 0.0900
r = 0.1000

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

답변 (1개)

Bhanu Prakash
Bhanu Prakash 2023년 3월 17일
편집: Bhanu Prakash 2023년 3월 17일
Hi Abu,
As per my understanding, you are facing some errors with the "for" loop.
Consider the line below:
plot(fidelity,r);
For the "plot" function to work, "r" must be of the same size as "fidelity", i.e., 1x15. If not, it throws an error.
To make "r" to be of size 1x15, the function "linspace" can be used.
I have made some changes in the code and the edited part of the code is attached below:
% Define the commutator of E and F
R_1 = E-F ;
r=linspace(0.01,0.1,15)
% Compute the exponential of R_1
for r_m=r
U = exp(0.01*(R_1));
With the help of "linspace", 15 equally spaced values are assigned to the matrix "r" and the "for" loop runs for 15 times, which is the size of "r".
You can refer to the documentation of "linspace" and "plot" functions, for more info:
Hope this answer helps you.
Thanks,
Bhanu Prakash.

카테고리

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