フィルターのクリア

[HELP] How to seperate cell with values greater than 230 into new cell.

3 ビュー (過去 30 日間)
awda
awda 2014 年 3 月 17 日
回答済み: dpb 2014 年 3 月 18 日
Hi
i have a problem seperating the Cell values with values greater than 230 into a new cell and values less than into another cell. i have data located in a 137242x1 Cell called V. and i want values bigger than 230 volt. to be imported into a new cell called Vnew.
This is supposed to be simple, but whenever i use > i get Error: Undefined function 'gt' for input arguments of type 'cell'.
its annoying...please help

採用された回答

Marta Salas
Marta Salas 2014 年 3 月 18 日
編集済み: Marta Salas 2014 年 3 月 18 日
Not efficent, but it will do the job:
v = {231.06;231.37;227.39;227.8}
thresh = 230;
vidx = cellfun(@(x) x > thresh, v)
for i=1:size(vidx)
if(vidx(i) ==1)
v{i,2} = v{i,1};
end
end
  1 件のコメント
awda
awda 2014 年 3 月 18 日
Thank you, this worked. i tried others method, but this was the one i wanted :D. thanks man

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

その他の回答 (5 件)

Kevin Claytor
Kevin Claytor 2014 年 3 月 17 日
cellfun is great for operating on cells;
v = {1,3,400, 3, 400, 5}
thresh = 230;
vidx = cellfun(@(x) x > thresh, v)
vnew = v(vidx)

dpb
dpb 2014 年 3 月 17 日
You have to dereference the content of the cell -- "use the curlies, Luke".
newV={V{:}>230);
See documentation on using cell arrays for more details/examples.
cellfun is useful, but overkill for the single case.
  2 件のコメント
awda
awda 2014 年 3 月 17 日
Thanks for answering, but i am afraid this does not do anything...i have tried that before. the errors i get is either:
Error using > Too many input arguments.
OR
Undefined function 'gt' for input arguments of type 'cell'.
dpb
dpb 2014 年 3 月 18 日
Sorry, overlooked that it's a cell array instead a cell with double array. Use the [ ] to enclose the returned list.
newV={[V{:}]>230);
See "comma list" in the doc for more on using the results from cell arrays.

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


awda
awda 2014 年 3 月 17 日
編集済み: awda 2014 年 3 月 17 日
i an afraid non of the above is working. i tried cellfun still no luck.
but maybe i have to clarify the question abit more :) here is an example on the picture attached.
i have all the data into 1 aray cell..i want the values with over 230 to be moved or copied into a new cell named newV.
thanks for help

awda
awda 2014 年 3 月 18 日
I thought it worked, but it did not :(..i activated V instead of ur v. but it stated an error. however i changed my cell into double...since it was string.

dpb
dpb 2014 年 3 月 18 日
Looks like your first cell isn't numeric but text. Use
Vnew=V([false [V{2:end}]>230]);
where the extra false in the resulting logical addressing vector accounts for the "off by one" error since not using the first entry.
A trivial example here...
>> V
V =
[0.0497]
[0.9027]
[0.9448]
...
[0.3692]
[0.1112]
[0.7803]
>> Vnew=V([false [V{2:end}]>0.5])
Vnew =
[0.9027]
[0.9448]
[0.9001]
[0.7803]
>>

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by