Whys isn't this if working?

4 ビュー (過去 30 日間)
Daniel Fonsêca
Daniel Fonsêca 2019 年 1 月 7 日
編集済み: Stephan 2019 年 1 月 7 日
I have this code:
if intervalo & quant == 0 %Caso seja um número
intervalo = str2num(nome);
quant = 1;
end
But, it isn't working. When this condicion is true, it doesn't work.
I'm using the '&' because I need to analyze vectores. Sometimes, intervalo is vectors, so I need to use that.
Thanks by the attention.
  1 件のコメント
Daniel Fonsêca
Daniel Fonsêca 2019 年 1 月 7 日
編集済み: per isakson 2019 年 1 月 7 日
I changed the value to 1, i say:
if intervalo & quant == 1 %Caso seja um número
intervalo = str2num(nome);
quant = 1;
end
And it worked. Why?

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

採用された回答

Stephan
Stephan 2019 年 1 月 7 日
編集済み: Stephan 2019 年 1 月 7 日
Hi,
consider:
>> intervalo = 0
intervalo =
0
>> quant = 0
quant =
0
Now case 1 - what you told Matlab to check:
>> intervalo & quant == 0
ans =
logical
0
Now the way what you problably wanted Matlab to do:
>> intervalo == 0 & quant == 0
ans =
logical
1
In other words:
If you write it the way you dit, it is the short way to write:
intervalo == 1 & quant == 0
is the same as:
intervalo & quant == 0
You got it?
Best regards
Stephan

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by