How can I find everything between two values?

1 回表示 (過去 30 日間)
Yunming Zhang
Yunming Zhang 2017 年 6 月 8 日
コメント済み: Image Analyst 2017 年 6 月 10 日
let's say I have the array and I was given another 2 X N array for the location of a value in the array
  • a b c d
  • e f g h
  • i j k l
  • how do I find values between two values using for loop, for example: how to I find 'e' if I was given the location of a&i, and find'b c' with the location of a and d. The two known values will always be in the same row or column.

採用された回答

Image Analyst
Image Analyst 2017 年 6 月 8 日
Try this, with your two coordinates (row1, col1) and (row2, col2)
if row1 == row2 % Rows are equal
output = m(row1, col1+1:col2-1);
else % Columns are equal
output = m(row1+1:row2-1, col1);
end
You'll have to check and make sure that 1 and 1 are not the same row and column so that there is actually something in between them. And make sure that 2 has larger columns or rows than 1. I didn't put in that kind of pre-validation of the row and column indexes but it's easy to do.
  4 件のコメント
Yunming Zhang
Yunming Zhang 2017 年 6 月 9 日
what if I want to go left to right as well as right to left?
Image Analyst
Image Analyst 2017 年 6 月 10 日
What does that mean? If you just want row1 to be the max instead of the min, just swap min and max inside deal().

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by