Get the last rows of tables inside a cell array
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Matt J
am 18 Mär. 2023
Bearbeitet: Matt J
am 18 Mär. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!