Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: What do these codes mean?

$
0
0
On 6/28/2013 11:02 PM, Chris Yoo wrote:
> What does this mean?:

Lmax=B(1,4);%Lmax is equal to the maximum value in the vector

The comment is true only if the preceding code has arranged it so that
is so...

> Also, if my inputs are 100,300,250, and 50, how will the value for Lmax,
> Lmin, La, and Lb turn out to be?
...

Well, I'd suggest just try it and see...

>
> here are the inputs
>
> L0=50,100,300
> L1=600,300,100
> L2=400,250,150
> L3=500,50,200
>
> fprintf('Enter Link Length\n')
> L0=input('Fixed link:');%input L0
> L1=input('Shorter Side Link:');%input L1
> L2=input('Coupler:');%input L2
> L3=input('Longer Side link:');%input L3
>
> A=[L0,L1,L2,L3];% arrange numbers into vector
> B=sort(A);%sort numbers from min to max
>
> Lmax=B(1,4);%Lmax is equal to the maximum value in the vector
> Lmin=B(1,1);%Lmin is equal to the minimum value in the vector
...

Lmax is only the max if there are a total of four elements in B --
you've concatenated four sets of three first so clearly that isn't going
to be so. The minimum will, of course, still be the first.

If want/need them sorted for some other reason, then the maximum one
will be B(end) (NB that the "1" first subscript for a 1D array/vector is
superfluous and can be omitted.)

doc min
doc max
doc end

Read "Getting Started" section

--

Viewing all articles
Browse latest Browse all 19628

Trending Articles