How to extract columns from cells in a cell array

6 vues (au cours des 30 derniers jours)
George kinyanjui
George kinyanjui le 18 Oct 2018
Commenté : Luna le 9 Nov 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.

Réponse acceptée

Luna
Luna le 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.
  2 commentaires
George kinyanjui
George kinyanjui le 18 Oct 2018
Oh my! You are spot on. You saved me on this. Thanks Luna. This one works like a charm!
Luna
Luna le 9 Nov 2018
Your welcome! :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by