1

Code

NA = 1.33; naValues = NA+pi/180:pi/180:(NA+pi/2); assert( (naValues > NA), 'naValues not bigger than NA'); 

where I also tried unsuccessfully floor(sum(naValues > NA))/90 in the place of the inequality that is trying assert( [logical], msg). Output

Error using assert The condition input argument must be a scalar logical. 

How can you use a vector inequality in Matlab's assert?

1
  • 1
    Use all or any to make it a scalar Commented Mar 18, 2016 at 15:00

2 Answers 2

2

Use all or any , but in general I would columnize the value you pass. This way it will always be robust to matrix and N-d arrays in addition to vectors. Observe:

>> matrixValues = reshape(naValues,10,9) matrixValues = Columns 1 through 7 1.34745329251994 1.52198621771938 1.69651914291881 1.87105206811824 2.04558499331768 2.22011791851711 2.39465084371654 1.36490658503989 1.53943951023932 1.71397243543875 1.88850536063819 2.06303828583762 2.23757121103705 2.41210413623648 1.38235987755983 1.55689280275926 1.7314257279587 1.90595865315813 2.08049157835756 2.25502450355699 2.42955742875643 1.39981317007977 1.57434609527921 1.74887902047864 1.92341194567807 2.09794487087751 2.27247779607694 2.44701072127637 1.41726646259972 1.59179938779915 1.76633231299858 1.94086523819802 2.11539816339745 2.28993108859688 2.46446401379631 1.43471975511966 1.60925268031909 1.78378560551853 1.95831853071796 2.13285145591739 2.30738438111682 2.48191730631626 1.4521730476396 1.62670597283904 1.80123889803847 1.9757718232379 2.15030474843733 2.32483767363677 2.4993705988362 1.46962634015955 1.64415926535898 1.81869219055841 1.99322511575785 2.16775804095728 2.34229096615671 2.51682389135614 1.48707963267949 1.66161255787892 1.83614548307836 2.01067840827779 2.18521133347722 2.35974425867665 2.53427718387609 1.50453292519943 1.67906585039887 1.8535987755983 2.02813170079773 2.20266462599716 2.3771975511966 2.55173047639603 Columns 8 through 9 2.56918376891597 2.74371669411541 2.58663706143592 2.76116998663535 2.60409035395586 2.77862327915529 2.6215436464758 2.79607657167524 2.63899693899575 2.81352986419518 2.65645023151569 2.83098315671512 2.67390352403563 2.84843644923507 2.69135681655558 2.86588974175501 2.70881010907552 2.88334303427495 2.72626340159546 2.9007963267949 >> all(matrixValues) ans = 1 1 1 1 1 1 1 1 1 >> all(matrixValues(:)) ans = 1 >> 
Sign up to request clarification or add additional context in comments.

7 Comments

Why did you particularly choose ...,10,9)?
Assume you fix the number of elements in a column to 10. You have 777 elements. How can you choose the optimum selection of items in column here? Simple hypothesis reshape(naValues, 10, ceil(N/10)).
I just picked the dimensions because that's what would produce a rectangular matrix in your example. I actually wasn't suggesting a reshape as part of the solution, I was just showing my recommendation to columnize your array - by saying naValues(:) - before calling all or any because it works not only for vectors but also for matrices and multi dimensional arrays
multiDimArray = rand(2,7,11,1,2); numel(all(multiDimArray)); numel(all(multiDimArray(:))) ans = 154 >> ans = 1
well it is a 5 dimensional array. a matrix is 2 dimensional and makes a rectangle. a 3d matrix makes a box. those are easy to visualize. beyond that you start getting into higher dimensions and yes they are harder to visualize. perhaps 4-d can be thought of as a box that changes shape through time. 5 dimensions gets harder to think about.
|
1

If you want all the naValues to be bigger than NA then you can make you vector comparison a scalar (required by assert) using the all function like this:

assert(all(naValues > NA)), 'naValues not bigger than NA'); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.