How to extract columns from cells in a cell array

14 次查看(过去 30 天)
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.

采纳的回答

Luna
Luna 2018-10-18
Could you please try:
output(k) = warp(p,q);
Because each time your output changes and it overrides your single scalar on it.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by