Azzera filtri
Azzera filtri

How do I extend cell to a larger dimension.

1 visualizzazione (ultimi 30 giorni)
I have a cell say A that I want to extend to the size of a larger cell, say B with special caracters, say 'n'. Similar to function padarray but with matrices. Say,
A = {'a','b';
'c','d'};
B = cell(3,4);
C = fun(A,size(B),'n')
gives
C = {'a','b','n','n';
'c','d','n','n';
'n','n','n','n' }
If it's not too much to ask I would like the MATLAB way to do it, either using indexing or a modification of padarray. Thank you.

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 18 Lug 2014
A = {'a','b';
'c','d'};
C = repmat({'n'},3,4)
[n,m]=size(A)
C(1:n,1:m)=A
  1 Commento
Diego
Diego il 18 Lug 2014
Thank you for your help. I was looking for an abstract way to do the last assignment.
[m,n] = size(A)
C(1:m,1:n) = A
The next step I found is:
[I1,I2] = ind2sub(size(C),1:numel(C));
C(I1 <= size(A,1) & I2 <= size(A,2)) = A;
And therefore would like something like,
C(ind2sub(size(C),1:numel(C)) <= size(A)) = A
But then I can't find the right parser for the indexing part...

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by