MATLAB Answers

0

How to choose only certain values my matrix answer

Asked by Krishma Gold on 12 Sep 2019
Latest activity Commented on by Krishma Gold on 14 Sep 2019
Hi. Grateful for any help please.
My output is in matrix, say 400 563 674 904 789
Now i want to use 563 to 904, as a matrix in another algorithm without me redefining it.
Many thanks

  0 Comments

Sign in to comment.

2 Answers

Answer by David Hill
on 12 Sep 2019

A=[400,563,674,904,789];
B=A(A>=563&A<=904);

  3 Comments

hi. Sorry may be i have not explained myself well.
Say my output is
400
563
674
904
789
i want to use this output in another algorithm but only these figures
400
563
674
904
should i use a loop?
Any help will be grateful. Many thanks
My B above gives you that output. If you want a column vector just add an apostrophe.
A=[400,563,674,904,789];
B=A(A>=563&A<=904)';

Sign in to comment.


Answer by Walter Roberson
on 14 Sep 2019

A=[400,563,674,904,789];
idx1 = find(A>=563, 1, 'first');
idx2 = find(A>=904, 1, 'first');
A(idx1:idx2)
but I suspect what you might be looking for is:
A(2:end-1)

  1 Comment

Thank you
you are right ....A(2:end-1).... works perfectly

Sign in to comment.