How to extract columns from cells in a cell array
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
George kinyanjui
el 18 de Oct. de 2018
Comentada: Luna
el 9 de Nov. de 2018
I have tried many examples available online but I am still not quite able to get what I desire. So my cell array is 1 x 123 and in each cell, there is a data structure (matrix) of dimension 10 x 8. Now I want to extract column 3:4 into a matrix q and column 6:7 into a matrix p, in each of the 123 cells. I try this in a loop so that each time, the code goes into cell{1,n} and generates matrices p and q, then runs a function script (warp) on the matrices p and q generated and finally stores the output in a .mat file. I want the script to keep appending result scalars on the output file until the last cell. In the end, I want to have a 123 x 1 matrix of output scalars. Here is my code:
format short g
numfiles = 123;
output = zeros(numfiles, 1);
mydata = cell(1, numfiles);
for k = 1:numfiles
filenames = sprintf('pid%d.xls', k);
mydata{k} = importdata(filenames);
a = mydata{1,k}.data; %I think this will only hold the kth cell data in the end.
q = a(:, 3:4);
p = a(:, 6:7);
output = warp(p,q);
end
This code runs but honestly I am sure I am not doing things right from the line I generate the `a` variable. Indeed I only get a single scalar as results in the end. Please help.
0 comentarios
Respuesta aceptada
Luna
el 18 de Oct. de 2018
Could you please try:
output(k) = warp(p,q);
Because each time your output changes and it overrides your single scalar on it.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!