how to use 'bool' function?

i am using matlab for seismic processing.plz help me with 'bool' function

1 commentaire

Adam
Adam le 8 Fév 2018
There's no such thing as the 'bool' function in base Matlab

Connectez-vous pour commenter.

Réponses (2)

KALYAN ACHARJYA
KALYAN ACHARJYA le 8 Fév 2018

1 vote

% A bool function means it returns to either true or false based on condition statement
if k==c % Condition statement
True statement;
else
False Statement
end

4 commentaires

John Wheater
John Wheater le 2 Oct 2019
Is it not better avoid a 'bool function', and instead to say
some_variable = (k==c);
then some_variable will be true or false.
Otherwise we're just saying
if true return true; else return false;end
btw how d'you get that neat coloured text into a post?
Stephen23
Stephen23 le 2 Oct 2019
"Is it not better avoid a 'bool function'..."
Yes
"how d'you get that neat coloured text into a post?"
By formatting the text as code (look above the comment box for formatting options).
John Wheater
John Wheater le 2 Oct 2019
Sorry, I see we don't have a boolean data type, and we get a matrix of 1s or zeros.
So a function is useful, but should maybe contain just the one line
return (k==c)(1);
Stephen23
Stephen23 le 2 Oct 2019
Modifié(e) : Stephen23 le 2 Oct 2019
"...we don't have a boolean data type, and we get a matrix of 1s or zeros."
Actually MATLAB has a logical type (displayed as 1s and 0s):
"So a function is useful..."
I don't see why. I would just write the logical comparison in my code.
"...but should maybe contain just the one line return (k==c)(1);"
That looks like a mixture of Python and MATLAB code (the keyword return does not return values in MATLAB, so that line performs some operations, discards any results, and then exits the function).

Connectez-vous pour commenter.

Walter Roberson
Walter Roberson le 8 Fév 2018

1 vote

There is no bool in MATLAB or Simulink. There is boolean in Simulink, which is not recommended https://www.mathworks.com/matlabcentral/answers/375074-erro-using-boolean-with-matlab-on-window-machine#answer_298242
The only place that bool appears in Mathworks related code is in some of the interfaces for generated C++ code.

Catégories

En savoir plus sur Seismology dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by