finding nth elements in multiple arrays

1 回表示 (過去 30 日間)
BoIs
BoIs 2016 年 11 月 7 日
コメント済み: BoIs 2016 年 11 月 7 日
I have multiple cell arrays: [93x2 double] [216x2 double] [128x2 double][121x2 double] [ 90x2 double] ...so on. These correspond to XY plots,
plot(a{i}(:,1),a{i}(:,2))
opens a plot which looks as fig attached. I want to get the Y values at 1/4th, 1/2 and 3/4th of X for all cells. How can I go about doing this?
Thanks
  4 件のコメント
BoIs
BoIs 2016 年 11 月 7 日
I want separate values for what Im doing. I want those numbers for each of the cells individually.
BoIs
BoIs 2016 年 11 月 7 日
Yeah I wanted X by position. Thanks for the answer!

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

採用された回答

Walter Roberson
Walter Roberson 2016 年 11 月 7 日
Presuming Y is in the second column and that you want the 1/4 by position instead of by range:
cellfun( @(C) C(round([end/4, end/2, 3*end/4]), 2), YourCell, 'Uniform', 0)
  1 件のコメント
BoIs
BoIs 2016 年 11 月 7 日
That worked! Thank you so much!

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

その他の回答 (1 件)

KSSV
KSSV 2016 年 11 月 7 日
a = {rand(93,2) ;rand(216,2) ; rand(128,2) ; rand(121,2) ; rand(90,2)} ;
data = cell2mat(a) ;
% plot(data(:,1),data(:,2),'r') ;
N = length(data) ;
%%1/4th value
data(N/4,:)
%%1/2 value
data(N/2,:)
%%3/4th value
data(3*N/4,:)
Note that N should be divisible by 1/4,1/2 and 3/4. In this case it was. If not you should use fix. For Ex. data(fix(N/4),:) etc.

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by