unpack cell array of letters to be plugged into individual-cell rows, in a vector
Show older comments
Dear Matlab,
I have a cell array of letters in each cell (they are channel labels), attached herein.
Eventually, I want to 'unpack' the string contents of each cell, and list them, in their own separate cell, splayed out as a row vector at the end of this below for-loop
(because in the end my GOAL is the have a list of channel locations on each experiment subject, with each subject on its own row)
(can even ignore the 1st 4 columns in the 'infon2' variable, and just make C as its own row, if easier). Hopefully this makes sense. Pls lmk if not.
as always, thanks much in advance for your help!!
Joanne
for k = 1:length(setl) % 'setl' is a list of file names for each subject
setlist = setl(k); %MAYBE CANT INDEX INTO A STRUCT
srate = num2str(200);
length1 = 2000;
ref = 3;
% initialize matrices on 1st subject
if k == 1
infon2 = strings([ length({setl.name}) 5 ]);
end % end initialization loop
infon2(k,:,:,:,:) = {num2str(k); srate; length1; ref; [c{:}]}';
close all;
end
4 Comments
Matt J
on 21 Jun 2023
Hopefully this makes sense. Pls lmk if not.
No, not to me. An example would be advisable.
Joanne Hall
on 21 Jun 2023
Joanne Hall
on 21 Jun 2023
Accepted Answer
More Answers (1)
Why are you storing numeric data as text? That must make data processing very awkward: most likely better data design would be to use e.g. a table, which lets you keep all of the data types of each column i.e. store and process numeric data as numeric.
S = load('infon2.mat');
C = S.infon2
N = size(C,1);
D = cell(N,0);
for k = 1:N
V = cellstr(C{k,5});
D(k,1:numel(V)) = V;
end
D = [C(:,1:4),D]
"eventually write out the complete lsit to an excel"
writecell(D,'mytable.xlsx')
8 Comments
Joanne Hall
on 22 Jun 2023
Joanne Hall
on 22 Jun 2023
C={'FP1-Ref', 'FP2-Ref'}
extractBefore(C,"-Ref")
Joanne Hall
on 22 Jun 2023
I would use either STRREP or REGEXPREP, which will not replace your data with "missing":
A = ["FP1-Ref", "FP2-Ref", "POL E", "POL PG1", "POL PG2"];
B = strrep(A,'-Ref','')
B = regexprep(A,'-Ref$','')
Note that "extracting before something" has no meaning when that something does not exist. In contrast, using the correct functions works as expected.
Joanne Hall
on 22 Jun 2023
Joanne Hall
on 22 Jun 2023
Edited: Joanne Hall
on 22 Jun 2023
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!