Changing the unknown variable in a matlab line

I have the following line in matlab:
y=sum(bin(xout>xout(1) & xout < -lim));
In the above line, Iam computing the value 'y' from known row-vectors 'bin' , 'xout', and known value 'lim'
How can I write the above equation, if I want to compute the value 'lim' if the value 'y' and row-vectors 'bin', 'xout' are now known.
%%---- Following scenario ---%% PICTURE ADDED
Please help

6 件のコメント

Image Analyst
Image Analyst 2012 年 8 月 16 日
Now known, or not known or unknown?
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 16 日
what is the lengtht of bin and xout, are they big?
zozo
zozo 2012 年 8 月 16 日
編集済み: zozo 2012 年 8 月 16 日
@ImageAnalyst: NOW known(already known). Find lim given y, bin, xout.
@Azzi: bin(1x200) and xout(1x6000).
Andrei Bobrov
Andrei Bobrov 2012 年 8 月 16 日
編集済み: Andrei Bobrov 2012 年 8 月 16 日
xout was sorted?
zozo
zozo 2012 年 8 月 16 日
no..its random
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 16 日
do you mean bin(1x6000) and xout(1x200)? because with bin(1x200) and xout(1x6000).
y=sum(bin(xout>xout(1) & xout < -lim));
don't work

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

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 16 日
編集済み: Azzi Abdelmalek 2012 年 8 月 16 日

0 投票

Example: run this to find y
bin=rand(20,1);xout=rand(20,1);lim=-0.5;
y=sum(bin(xout>xout(1) & xout < -lim));
then run this to find lim
lim=[];
for k=1:length(xout);
if sum(bin(xout>xout(1) & xout < xout(k)))==y;
lim=[lim -xout(k)]
end
end
lim=max(lim)
note: you will notice that lim is not exactly the same as the first. and if lim contains many values, you choose the bigest (-lim will be the smaller)

3 件のコメント

zozo
zozo 2012 年 8 月 16 日
@azzi: It is returning an empty variable 'lim'. It works for ur example(but not for all values)
*note: I have added a picture in my question, please have a look*
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 8 月 16 日
編集済み: Azzi Abdelmalek 2012 年 8 月 16 日
if y is given by
y=sum(bin(xout>xout(1) & xout < -lim));
lim can't be empty, unless you impose y. in this case, it's possible that lim will be empty
zozo
zozo 2012 年 8 月 16 日
I changed:
if sum(bin(xout>xout(1) & xout < xout(k)))==y;
to
if sum(bin(xout>xout(1) & xout < xout(k)))<=y;
and now it works! Thanks Azzi

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2012 年 8 月 16 日

0 投票

How about (untested)
% Get area as function of xout.
cumulativeSum = cumsum(bin);
% For a given area, called desiredArea,
% find the index where the cumulative sum first exceeds that area.
lim = find(cumulativeSum >= desiredArea, 1, 'first');
% lim was the index. Now find the xout value at that index:
xOutValue = xout(lim);

1 件のコメント

zozo
zozo 2012 年 8 月 16 日
thanku @image analyst

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

カテゴリ

ヘルプ センター および File ExchangeConstruction についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by