How to extract columns from cells in a cell array
13 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Luna
on 18 Oct 2018
Could you please try:
output(k) = warp(p,q);
Because each time your output changes and it overrides your single scalar on it.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!