Filter löschen
Filter löschen

Choosing specific column within cells

2 Ansichten (letzte 30 Tage)
Yaashiene Pukazhendi
Yaashiene Pukazhendi am 22 Mär. 2023
Bearbeitet: Stephen23 am 22 Mär. 2023
Hi.
I have a 1x50 cell and each of the cells contain varying size of matrices. I would like to choose specific columns in each of the cell and place those columns into a separate function. How would I go about doing this? I have included my code for reference
for k = 1:numel(C)
F = fullfile(P,C(k).name); % P refers to the filepath and C are the chosen files within the filepath
C(k).data = readmatrix(F);
Ccell = {C.data};
cycle = Ccell(2:51); % I only want to choose C files from C(2) to C(51)
end
for i=1:50
cellV{i}= cycle{1,:}(:,16:25);
% Within these 50 C files(now in cell format), I would like to pick columns 16:25 from each C cell and place them into a function called cellV
end
  1 Kommentar
Stephen23
Stephen23 am 22 Mär. 2023
Bearbeitet: Stephen23 am 22 Mär. 2023
Move these two lines after the loop (there is no point in running them on every loop iteration, because your code anyway only keeps the last iteration's results, and discards all the previous iterations' results):
Ccell = {C.data};
cycle = Ccell(2:51);
Note that you can also use indexing directly in the comma-separated list, i.e. you can replace both of those lines with this:
cycle = {C(2:25).data};

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 22 Mär. 2023
Why not just use the same loop? There does not seem to be any point in using a second loop.
for k = 1:numel(C)
F = fullfile(P,C(k).name); % P refers to the filepath and C are the chosen files within the filepath
M = readmatrix(F);
C(k).data = M(:,16:25);
end
Ccell = {C(2:end).data} % optional

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by