How to extract columns from cells in a cell array

14 Ansichten (letzte 30 Tage)
George kinyanjui
George kinyanjui am 18 Okt. 2018
Kommentiert: Luna am 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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by