Help with linspace and indexing

8 ビュー (過去 30 日間)
Jason
Jason 2015 年 11 月 3 日
回答済み: Image Analyst 2015 年 11 月 3 日
I have a vector of values where "roughly" the middle value is close to zero. It can be positive or negative. (these represent real locations on an fluorescent image of a regular pitched object array)
xactual=
-30.6552
-23.6552
-17.6552
-11.6552
-5.6552
0.3448
6.3448
12.3448
18.3448
24.3448
30.3448
36.3448
I want to be able to subtract this offset (0.34 in this case) off all of the values, so I tried:
xactualZero=min(abs(xactual(:)))
xactual=xactual-xactualZero;
However this doesnt handle the sign, as I said this value closest to zero can be positive or negative.
Also I want to find the index of this value (thats closest to zero) and create a linspace vector of equal length, starting with zero in the same location, but increment positively and negatively by 6 units. i.e
xreal=
-30
-24
-18
-12
-6
0
6
12
18
24
30
36
I am trying to calculate optical distortion and have the "actual locations" of my objects that I know are 6 pixels seperated I can work out the distortion as
dist=xreal-xactual.

採用された回答

Jan
Jan 2015 年 11 月 3 日
編集済み: Jan 2015 年 11 月 3 日
[dummy, index] = min(abs(xactual(:)))
xactualZero = xactual(index);
xactual = xactual - xactualZero;
If your problem is almost solved by the min function, reading the documentation of this command will help you. If it is not solved by a specific option of the command, look at the "See also" line on the bottom. This is extremely useful.
  3 件のコメント
Stephen23
Stephen23 2015 年 11 月 3 日
編集済み: Stephen23 2015 年 11 月 3 日
>> 6*((1:numel(xactual))-index)
ans =
-30 -24 -18 -12 -6 0 6 12 18 24 30 36
Or do you particularly need to use linspace?
Jason
Jason 2015 年 11 月 3 日
Thats perfect, thankyou. How do I accept both of your answers?

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 11 月 3 日
You might be interested in imregionalmin() or imregionalmax().

カテゴリ

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