Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask MATLAB Expert

Representing Logical true and False:

It has been stated that expressions which are theoretically true really have the integer value of 1, and expressions which are theoretically false really have the integer value of 0.Exhibiting the concepts of logical true and false in the MATLAB is somewhat different: the concept of false is presented by the integer value of 0, but the concept of true can be presented by any non-zero value (not merely the integer 1). This can lead to a few strange Boolean expressions. For illustration, consider the following if statement:

>> if 5

disp('Yes, this is true!')

end

Yes, this is true!

As 5 is a nonzero value, it is a way of telling true. And hence, when this Boolean expression is computed, it will be true, therefore the disp function will be executed and "Yes, this is true" is exhibited. Obviously, this is a pretty bizarre if the statement, one that hopefully would not ever be encountered!

Though, a simple mistake in an expression can lead to this type of answer. For illustration, let's state that the user is prompted for the choice of Y or N for a yes/no question:

letter = input('Choice (Y/N): ','s');

In the script we might want to execute a specific action if the user responded with 'Y'. Nearly all scripts would permit the user to enter either lower- or uppercase (example, either 'y' or 'Y') to specify yes. The appropriate expression that would return true if the value of letter was 'y' or 'Y' would be

letter == 'y' || letter == 'Y'

Though, if by fault this was written as:

letter == 'y' || 'Y'

this expression would  forever be true, regardless of the value of the variable letter. This is as 'Y' is a nonzero value; therefore it is a true expression. The first section of the expression might be false, but as the second expression is true the whole expression would be true.

MATLAB, Engineering

  • Category:- MATLAB
  • Reference No.:- M9512482

Have any Question?


Related Questions in MATLAB

Assignmentq1 find the laplace transforms of the following

Assignment Q.1 Find the Laplace transforms of the following functions: (a) t 2 + at + b and (b) sin(2nΠt/T) Q.2 Find f (t) for the following F(s) = α[ f (t)]. (i) 5/(s + 3), (ii) 1/s 2 + 25, (iii) 1/s(s+1) Q.3 Find the L ...

Assignment -matlab codes and simulated model in

Assignment - Matlab codes and simulated model in simulink/matlab and truetime. 1. Matlab codes and simulink model for pid controller optimization using particle swarm optimization (PSO) my plant is integer order 1000/(s^ ...

Lab assignment - matlab matrix relationallogical operators

Lab Assignment - MATLAB Matrix, Relational/Logical Operators and Plotting This laboratory exercise/assignment will involve you 1) practicing multiplication operators in MATLAB; 2) practicing relational and logical operat ...

Assignment - matlab programmingusing appropriate matlab

Assignment - MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

Assignment details -need to write a code for connecting

Assignment Details - Need to write a code for connecting segments (Lines) a special case of TSP. The problem is to connect lines in 2d/ 3d space with path obstructions. Can you help me write the code for this? Hope you m ...

What comparison of means test was used to answer the

What comparison of means test was used to answer the question

Discrete optimisation- solve the following two problems

Discrete Optimisation - Solve the following two problems with both exhaustive enumeration and branch and bound - Problem 1 is a mixed integer linear optimisation problem (the problem has both discrete and continuous vari ...

Assignment -we have daily gridded rainfall data of 40 years

Assignment - We have daily gridded rainfall data of 40 years and structure of the dataset is like below; Lat = [6.5:0.25:38.5]; Lon = [66.5:0.25:100]; Rainfall (135x129x365x40) (Lon, Lat, days, years). Now, we looking fo ...

Question 1 manipulate spectral imagehyperspectral images

Question 1. Manipulate spectral image Hyperspectral images can be seen as a generalisation of normal colour images such as RGB images. In a normal RGB colour image, there are 3 channels, i.e. channels for red colour, gre ...

Assignment -data is given on which want to do computational

Assignment - Data is given on which want to do computational production planning using Metaheuristic MATLAB Programming: 1) Ant Colony Algorithm on both Partial and Total Flexible Problem. 2) Bee Algorithm on both Partia ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As