find maximum value indices

Im trying to find the indices number of the max of a certain function.
delcx(:,n) = (massch4(max(longm(dataind{n}))))
I want to find the massch4 at the location where longm is a max value. Can I do that in one line? Can I use the find function?
Thanks!

10 件のコメント

per isakson
per isakson 2015 年 2 月 10 日
編集済み: per isakson 2015 年 2 月 10 日
Why should we guess regarding massch4, longm and dataind? Please tell us about class, size and value. An example might be appropriate.
shobhit mehrotra
shobhit mehrotra 2015 年 2 月 10 日
Hello,
massch4 is 1x30000 vector
longm is 1x30000 vector
dataind contains of indices stored in an array
per isakson
per isakson 2015 年 2 月 10 日
編集済み: per isakson 2015 年 2 月 10 日
  • "Can I do that in one line?" &nbsp It's easier to break it up in small steps and confirm that it works correctly. Lastly, one may combine it into one line.
  • "in an array" &nbsp cell array I assume
ixn = dataind{ n };
lgm = longm( ixn );
mxl = max( lgm );
ms4 = massch4( mxl );
mxl and ms4 will be scalars. Will lgm and mxl be whole number suitable as indicies? What did I miss?
shobhit mehrotra
shobhit mehrotra 2015 年 2 月 10 日
編集済み: per isakson 2015 年 2 月 10 日
Hi it works, but this for a For Loop, how would I modify it, I tried to subscript (n) but it didnt work
this is what i got
for n=1:20
ixn(n) = longm(dataind{ n });
lgm(n) = longm( ixn );
mxl(n) = max( lgm );
ms4(n) = massch4( mxl );
end
Thanks!
per isakson
per isakson 2015 年 2 月 10 日
編集済み: per isakson 2015 年 2 月 10 日
This looks strange! Why
ixn(n) = longm(dataind{ n });
rather than
ixn(n) = dataind{ n };
Isn't it time you
  • start using the {}Code button and
  • provide some sample data: input and required output
shobhit mehrotra
shobhit mehrotra 2015 年 2 月 10 日
編集済み: per isakson 2015 年 2 月 10 日
Can I use this function
for n=1:20
indm(n)= (find(longm == max(longm((dataind{n})))))
end
The output should be a vector of indices of length n.
Thanks
per isakson
per isakson 2015 年 2 月 10 日
編集済み: per isakson 2015 年 2 月 10 日
Did you try it? Whether it will work or not depends on the input data. You might preallocate memory for indm.
indm = nan(1,20);
for n=1:20
indm(n) = find( longm == max(longm(dataind{n})) );
end
What happened to massch4?
shobhit mehrotra
shobhit mehrotra 2015 年 2 月 10 日
It works except if there is more than one indices it lists them both, I want it to only list the first indices in case of more than one. Thanks
shobhit mehrotra
shobhit mehrotra 2015 年 2 月 10 日
I have that in another line, once I can get the indices Ill substitute it in
per isakson
per isakson 2015 年 2 月 10 日
Replace
find( longm == max(longm(dataind{n})) )
by
find( longm == max(longm(dataind{n})), 1, 'first' )

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

回答 (0 件)

カテゴリ

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

製品

質問済み:

2015 年 2 月 10 日

コメント済み:

2015 年 2 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by