What is the shortest way to check the followings?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
- non-negative real scalar
- real valued vector having the length 2
- real valued numeric cell array containing 2 elements (length 2 also)
0 comentarios
Respuestas (2)
Image Analyst
el 14 de Jun. de 2015
Editada: Image Analyst
el 14 de Jun. de 2015
Hints: These functions may be useful isreal(), real(), length(), and isvector(). And, obviously the ">= 0" and "==" operations. I don't think you should need additional help beyond this.
4 comentarios
Jan
el 14 de Jun. de 2015
@Mr M: How do you define "shorter"? The run time of the command will not matter. Then the readability during debugging has the largest effect. Therefore the standard methods are optimal, although you might be able to create a cryptic command which is 1 or 2 characters shorter.
Image Analyst
el 15 de Jun. de 2015
You said "my question was about any tricky method which is shorter or any predefined function which can be useful." You did not mention requiring a "tricky method" so I gave you the "predefined/built-in methods". Since you are now asking about tricky or predefined methods, then the predefined methods I listed should be sufficient. No need for tricks.
Mr M.
el 15 de Jun. de 2015
11 comentarios
dpb
el 17 de Jun. de 2015
"Except that MATLAB doesn't see it that way..."
Precisely; that was my point re: "quality of implementation" (for lack of better nomenclature). That there are "issues" regarding memory on how it's used are certainly true but generally optimizers these days should be able to deal with what can be dealt with. If, otoh, the complex part is there, it's there and memory is required to deal with it (which may, depending upon how something is written, have the consequence one can't do as large a problem as one might if one took advantage of knowing a priori that the imaginary part is going to end up going away.
I'm not arguing strongly that it should be changed; simply noting that it fooled me after 30 year w/ Matlab as I was expecting it to be.
James Tursa
el 17 de Jun. de 2015
Once TMW embraced the philosophy of getting rid of identical 0 imaginary parts in calculation results, I think they were stuck. For the following two constructs:
a = 1 + 0i;
z = 0;
b = 1 + z*1i;
I think you could probably get a high percentage of votes that they should yield identical results for a and b (imaginary part physically removed), and another camp voting the opposite (the user typed in 0i explicitly so they must have wanted a complex result with 0 imaginary part physically present).
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!