how to add string matrix to numeric matrix?
46 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
example:
from
a=[rice;corn;wheat]
b=[3;4;3]
become
c=[rice 3;corn 4;wheat 3]
0 Commenti
Risposte (3)
José-Luis
il 26 Ott 2012
You could use cell arrays:
a={'rice';'corn';'wheat'};
b={3;4;3};
your_result = cellfun(@(a,b) [a ' ' num2str(b)],a,b,'uniformoutput',false);
4 Commenti
Walter Roberson
il 26 Ott 2012
[a, strcat({' '}, num2str(b))] %output will be cell 3x2 of strings
Walter Roberson
il 26 Ott 2012
No, numeric arrays can never contain strings.
Cell arrays can contain both strings and numbers, in separate elements.
c = {'rice', 3; 'corn', 4; 'wheat', 3};
2 Commenti
Walter Roberson
il 26 Ott 2012
Modificato: Walter Roberson
il 26 Ott 2012
c = [a, num2cell(b)]; %output will be cell 3x2 first col strings second col numeric
Azzi Abdelmalek
il 26 Ott 2012
a={'rice';'corn';'wheat'}
b=[3;4;3]
c=arrayfun(@(x) [a{x} ' ' num2str(b(x))],1:3,'un',0)
0 Commenti
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!