Storing results from a for loop into a cell array vector
Ältere Kommentare anzeigen
Code so far:
C = {'TGC','TGT'};
D = {'ATA','ATC','ATT'};
k = length(C)*length(D);
V = cell(k,1);
for i=1:length(C)
for j=1:length(D)
V = strcat(C(i),D(j))
end
end
Output:
V =
'TGCATA'
V =
'TGCATC'
V =
'TGCATT'
V =
'TGTATA'
V =
'TGTATC'
V =
'TGTATT'
I just want to store those results in a single vector V. Thanks!
Akzeptierte Antwort
Weitere Antworten (3)
Azzi Abdelmalek
am 15 Aug. 2013
nc=numel(C);
nd=numel(D)
ii=repmat(1:nc,1,nd)
jj=repmat(1:nd,nc,1)
out=arrayfun(@(x,y) [C{x} D{y}],ii',jj(:),'un',0)
...
for i=1:length(C)
for j=1:length(D)
V{i, j} = [C{i}, D{j}];
end
end
Now you store all results in the cell V, but what does "in a single vector" mean?
1 Kommentar
Azzi Abdelmalek
am 15 Aug. 2013
He means V(:)
Kategorien
Mehr zu Operators and Elementary Operations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!