Cell array to meet conditions and cell indexing
2 ビュー (過去 30 日間)
古いコメントを表示
I apologise in advance for incase this is unclear.
I have an array, with X Y columns and another column that identifies the other X and Ys that have met a previous condition. For example A=[16x1 double 16x1 double 8; 12x1 double 12x1 double []; 15x1 double 15x1 double [13,15]..... up to 19 rows]. If the condition was not met there is no match and so the third column reads [], as given for A(2,:). If two sets of x and y coordinates have been matched, then these can be found in rows 13 and 15 for example of column 1, for A(3,:).
I want to therefore have an output of the original X and Y sets, the matching rows (I already have) and the matching X Y coordinates. I had had numerous errors since there are empty cells, which I do not want to delete. Also, the number of matches changes each time, so concatenating brings errors.
Thankyou.
2 件のコメント
Stephen23
2016 年 2 月 22 日
Please at least give us the arrays to work with. Edit your question, click the paperclip button, then both Choose file and Attach file buttons.
採用された回答
Guillaume
2016 年 2 月 22 日
I'm not really clear on the format of the output you want, but the following should give you an idea what to do:
C = {[1:10]', [21:30]', 8; [41:45]', [51:55]', [2 4]; [60:70]', [80:90]', []} %demo data
C(:, 4) = cellfun(@(x, y, row) [x(row), y(row)], C(:, 1), C(:, 2), C(:, 3), 'UniformOutput', false)
celldisp(C(:, 4))
5 件のコメント
Guillaume
2016 年 2 月 23 日
The loop solution should have read:
rows = X_Y_Match{rowidx, 3};
Sorry about the typo.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!