Get the last rows of tables inside a cell array
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I want to get the last rows of each table inside a cell array. I try to solve this without a loop because the cell array is quite big.
a = cell(1, 50);
b = rand(780, 6);
a(:) = {table(b(:, 1), b(:, 2), b(:, 3), b(:, 4), b(:, 5), b(:, 6))};
Now in my case the tables inside the cells all have the same column names but different. I tried
c=vertcat(a{:}(end,:))
and different indexing but I can't get it to work.
Intermediate brace '{}' indexing produced a comma-separated list with 50 values, but it must produce a single value when followed by subsequent indexing operations.
How can I solve this?
Thank you very much!
0 Commenti
Risposte (1)
Matt J
il 18 Mar 2023
Modificato: Matt J
il 18 Mar 2023
There is no way to avoid the slow speed of a loop when dealing with cell arrays. Cell arrays are not meant to be fast. However, you can abbreviate the loop syntax by doing,
a = cell(1, 50);
b = rand(780, 6);
a(:) = {table(b(:, 1), b(:, 2), b(:, 3), b(:, 4), b(:, 5), b(:, 6))};
c=cellfun(@(z) z(end,:) ,a,'uni',0)
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!