what does == mean in script

13 ビュー (過去 30 日間)
Benjamin Garvin
Benjamin Garvin 2013 年 11 月 20 日
コメント済み: Benjamin Garvin 2013 年 11 月 20 日
hi im writing a piece of script for course work and would like comment each of the lines that i have used, could you help me and tell me what using == does when putting it into my script,
Thanks
Ben
N=-1:5;% sets the values on the x axis I want to use
x1=[1 2 2 1 4 0 0];
for n=1:7
if n==1
y1(1,n)=x1(1,n);
else y1(1,n)=x1(1,n)+y1(1,n-1);
end
end
stem(N,y1)

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 20 日
a==b
returns 1 if a and b are equal, it returns 0 if not. type
1==4 % check the result
4==4 % check the result
  1 件のコメント
Benjamin Garvin
Benjamin Garvin 2013 年 11 月 20 日
Thanks for your help Azzi

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


Image Analyst
Image Analyst 2013 年 11 月 20 日
It's used to compare two variables (numbers, arrays, etc.) and say whether they match or not. This is different than a single = sign, which is an assignment. In a==b you'll get a single true or false value, or an array of them if a and b are arrays. In a=b, you're taking the value of b and stuffing it into a, overwriting any prior value that a had, or creating a brand new variable a if no variable by that name existed yet.

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by