How to get a charachter vector from a cell array?

6 visualizzazioni (ultimi 30 giorni)
I used to have a charachter vector like:
bound = ['c', 'f', 'f', 'f'];
And I got:
bound(1) = 'c'
bound(2) = 'f'
but then I needed to change it and have right now:
bound = ['ctb', 'f', 'f', 'f'];
but if I want to acces bound(1) I get just:
bound(1) = 'c'
But I need:
bound(1) = 'ctb'
So I thought i can use cells instead of char so i changed my code:
bound = {'ctb', 'f', 'f', 'f'};
And I get also
bound(1) = 'ctb'
But this is no more a character vector and I can't use it with mkdir to create folders. If you convert
char(bound)
you get an character array instead of a character vector. Also
strcat(bound)
remains a cell array. So how can I use mkdir with cell arrays or convert cell arrays to character vectors?
Just for clarification I use it late like this where numa, tnm, lxnum, npnum, stiffnum are integers and method is also a character vector:
nameap = [num2str(numa),'-',num2str(tnm), ...
'-',num2str(lxnum),'-',num2str(npnum), ...
'-',num2str(stiffnum),'-',strcat(bound),'-',method]; %Appendix of folders and files
simfol = ['sim-',nameap]; %simulation folder name
mkdir(char(simfol)); %Create folder for the simulation
Ans I use R2016b.

Risposta accettata

Adam Danz
Adam Danz il 16 Lug 2018
Modificato: Adam Danz il 16 Lug 2018
bound = {'ctb', 'f', 'f', 'f'};
bound(1) % {'ctb'}, cell
bound{1} % 'ctb', char
bound{1}(1) % 'c', char
  2 Commenti
Samuel Augustiny
Samuel Augustiny il 16 Lug 2018
so to get a character vector I should use
boundchar = [bound{1},bound{2},bound{3},bound{4}];
It functions but there doesen't exist a more elegant way?
Adam Danz
Adam Danz il 16 Lug 2018
Modificato: Adam Danz il 16 Lug 2018
This produces the same results as your line above (but is much more efficient and it's what you're looking for).
boundchar = [bound{:}]

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Encryption / Cryptography in Help Center e File Exchange

Prodotti


Release

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by